`

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

 
阅读更多
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();
}


}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics