网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

JAVA复制的代码 java复制的代码运行错误

java文件复制粘贴

复制粘贴实际上是文件的流读取和写入可以通过如下方法实现:

在陇县等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供成都网站建设、网站建设 网站设计制作按需制作,公司网站建设,企业网站建设,品牌网站制作,全网整合营销推广,外贸营销网站建设,陇县网站建设费用合理。

读写是两个不同的分支,通常都是分开单独使用的。

可以通过BufferedReader 流的形式进行流缓存,之后通过readLine方法获取到缓存的内容。

BufferedReader bre = null;

try {

String file = "D:/test/test.txt";

bre = new BufferedReader(new FileReader(file));//此时获取到的bre就是整个文件的缓存流

while ((str = bre.readLine())!= null) // 判断最后一行不存在,为空结束循环

{

System.out.println(str);//原样输出读到的内容

};

备注: 流用完之后必须close掉,如上面的就应该是:bre.close(),否则bre流会一直存在,直到程序运行结束。

可以通过“FileOutputStream”创建文件实例,之后过“OutputStreamWriter”流的形式进行存储,举例:

OutputStreamWriter pw = null;//定义一个流

pw = new OutputStreamWriter(new FileOutputStream(“D:/test.txt”),"GBK");//确认流的输出文件和编码格式,此过程创建了“test.txt”实例

pw.write("我是要写入到记事本文件的内容");//将要写入文件的内容,可以多次write

pw.close();//关闭流

备注:文件流用完之后必须及时通过close方法关闭,否则会一直处于打开状态,直至程序停止,增加系统负担。

java 从网上复制的代码没有错,但一改里面的一个方法名就报错

Dic是没有定义的类,如果是你自己写的类,用import yourpackage.Dic导入,如果是第三方包,也要用import语句把类导入

使用Java语言如何实现快速文件复制

使用Java语言如何实现快速文件复制:

代码:

import java.io.File;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

import java.nio.channels.FileChannel;

public class Test {

public static void main(String[] args){

long start = System.currentTimeMillis();

FileInputStream fileInputStream = null;

FileOutputStream fileOutputStream = null;

FileChannel inFileChannel = null;

FileChannel outFileChannel = null;

try {

fileInputStream = new FileInputStream(new File("C:\\from\\不是闹着玩的.flv"));

fileOutputStream = new FileOutputStream(new File("C:\\to\\不是闹着玩的.flv"));

inFileChannel = fileInputStream.getChannel();

outFileChannel = fileOutputStream.getChannel();

inFileChannel.transferTo(0, inFileChannel.size(), outFileChannel);//连接两个通道,从in通道读取数据写入out通道。

} catch (IOException e) {

e.printStackTrace();

} finally {

try {

if(fileInputStream != null){

fileInputStream.close();

}

if(inFileChannel != null){

inFileChannel.close();

}

if(fileOutputStream != null){

fileOutputStream.close();

}

if(outFileChannel != null){

outFileChannel.close();

}

} catch (IOException e) {

e.printStackTrace();

}

}

long end = System.currentTimeMillis();

System.out.println("视频文件从“from”文件夹复制到“to”文件需要" + (end - start) + "毫秒。");

}

}

急求:JAVA编写复制文件夹的代码

一个简单的方式就是调用cmd命令,使用windows自带的功能来替你完成这个功能

我给你写个例子

import java.io.*;

public class test{

public static void main(String[] args){

BufferedReader in = null;

try{

// 这里你就当作操作对dos一样好了 不过cmd /c 一定不要动

Process pro = Runtime.getRuntime().exec("cmd /c copy d:\\ReadMe.txt e:\\");

in = new BufferedReader(new InputStreamReader(pro.getInputStream()));

String str;

while((str = in.readLine()) != null){

System.out.println(str);

}

}catch(Exception e){

e.printStackTrace();

}finally{

if(in != null){

try{

in.close();

}catch(IOException i){

i.printStackTrace();

}

}

}

}

}


本文标题:JAVA复制的代码 java复制的代码运行错误
网站链接:http://bjjierui.cn/article/dosoeic.html

其他资讯