把一个文件复制到另外一个文件中

public static void main(String[] args) {

//需要复制的文件
File oldFile = new File("E:\\upload\\123.txt");

//新的文件路径
File newFile = new File("E:\\upload\\123.txt");

try {
FileInputStream fileStream = new FileInputStream(oldFile);
FileOutputStream fileOut = new FileOutputStream(newFile);

int read = 0;
while ((read = fileStream.read()) != -1) {
fileOut.write(read);
fileOut.flush();
}

fileOut.close();
fileStream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}


}

猜你喜欢

转载自liushuifeiyu.iteye.com/blog/2389654