java 把a文件复制到b

来源:百度知道 编辑:UC知道 时间:2024/05/10 12:22:28
这是我自己写的程序,可是怎么也不能把a.txt复制到b.txt中,请高手指点我下:
import java.io.*;
class MyCopy{
public static String tellfile(){
String str = null;
try{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
str = br.readLine();
}catch(IOException e){
e.printStackTrace();
System.out.println("输入错误");
}
return str;
}
String out = null;
public static String mycopy(String in,String out ){
try{
FileReader fr = new FileReader(in);
BufferedReader br = new BufferedReader(fr);

FileWriter fw = new FileWriter(out);
BufferedWriter bw = new BufferedWriter(fw);

PrintWriter pw = new PrintWriter(bw);
while(br.read()!=-1){
pw.print(out);
}
}catch(FileNotFoundException e){
e.printStackTrace();
}
catch(IOException e){
e.printStackTrace();
}

return out;

复制文件,如图片,音乐文件,建议用字节流.

你没有关闭流.

在mycopy方法的while块后添加下面两行.
br.close();
bw.close();

我写的小例子.
package test;

import java.io.*;

public class FileTest{
public static void main(String[] args){

File from=new File("src\\test\\FileTest.java");
File to=new File("src\\xxxx\\FileTest2.java");
copyFile(from,to);
}
public static void copyFile(File from,File to){
BufferedInputStream in=null;
BufferedOutputStream out=null;
try{
if(!from.exists()){
return;
}
if(!to.exists()){
File toDir=new File(to.getParent());
toDir.mkdirs();
to.createNewFile();
}
in=new BufferedInputStream(new FileInputStream(from));
out=new BufferedOutputStream(new FileOutputStream(to));
int b=0;
while((b=in.read())!=-1){
out.write(b);

在纯DOS下怎么把A机的文件复制到B机上呢? 把A计算机的系统文件完全复制到B计算机里,B计算机可以正常启动吗? 为什么我把文件夹A里的图片复制到文件夹B(B里本来就有图),然后在删除A的图.整个B文件都会不见 如何在dos下,把文件复制到a盘啊??? 在CAD里如何把文件A里的布局复制在文件B里 如果要将A文件夹里的所有文件复制到B文件夹 而B中有的文件不要复制 没有的才复制 怎么办 我从A电脑把[*.ID]文件复制到B电脑,而在B电脑下的[*ID]文件图标却改变不可用了,是什么原因?怎样操作.急盼! ??我有两个硬盘A和B.我想把B中的系统复制到A中.并格式化A中的C盘,该怎么做呀 ?我有两个硬盘A和B.我想把B中的系统复制到A中.并格式化A中的C盘,该怎么做呀 复制A文件夹下多个且多层子目录下的所有文件到B文件夹用什么命令?