java中如何将一个文件中的内容copy到另一个文件中
str=in.readLine();Filef1=newFile(str);str=in.readLine();Filef2=newFile(str);if(f1.isF...
str = in.readLine();
File f1 = new File(str);
str = in.readLine();
File f2 = new File(str);
if(f1.isFile() && f2.isFile()){
FileReader reader=new FileReader(f1);
FileWriter Writer=new FileWriter(reader.read()); 展开
File f1 = new File(str);
str = in.readLine();
File f2 = new File(str);
if(f1.isFile() && f2.isFile()){
FileReader reader=new FileReader(f1);
FileWriter Writer=new FileWriter(reader.read()); 展开
1个回答
展开全部
方式一:
File file1 = new File("D:/1.txt");
File file2 = new File("D:/2.txt");
if(file1.isFile() && file2.isFile()){
FileInputStream fis = new FileInputStream(file1);
FileOutputStream fos = new FileOutputStream(file2);
byte [] buffer = new byte[1024];
int len = 0;
while((len = fis.read(buffer)) != -1){
fos.write(buffer,0,len);
}
}
方式二:
File file1 = new File("D:/1.txt");
File file2 = new File("D:/2.txt");
if(file1.isFile() && file2.isFile()){
FileReader reader = new FileReader(file1);
FileWriter writer = new FileWriter(file2);
int len = 0;
while((len=reader.read()) != -1){
writer.write(len);
}
writer.flush();
}
File file1 = new File("D:/1.txt");
File file2 = new File("D:/2.txt");
if(file1.isFile() && file2.isFile()){
FileInputStream fis = new FileInputStream(file1);
FileOutputStream fos = new FileOutputStream(file2);
byte [] buffer = new byte[1024];
int len = 0;
while((len = fis.read(buffer)) != -1){
fos.write(buffer,0,len);
}
}
方式二:
File file1 = new File("D:/1.txt");
File file2 = new File("D:/2.txt");
if(file1.isFile() && file2.isFile()){
FileReader reader = new FileReader(file1);
FileWriter writer = new FileWriter(file2);
int len = 0;
while((len=reader.read()) != -1){
writer.write(len);
}
writer.flush();
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询