当前位置: 技术问答>java相关
How to create a new file? THANKS
来源: 互联网 发布时间:2015-07-12
本文导语: How to create a new file? THANKS 1. There is a file--file.txt. I want to create a new file--filecopy.txt. how to do? I want to get a best and simple method!! thank you!! | FileWriter fWriter = new FileWriter("filecopy....
How to create a new file? THANKS
1.
There is a file--file.txt. I want to create a new file--filecopy.txt. how to do? I want to get a best and simple method!!
thank you!!
1.
There is a file--file.txt. I want to create a new file--filecopy.txt. how to do? I want to get a best and simple method!!
thank you!!
|
FileWriter fWriter = new FileWriter("filecopy.txt");
if you want copy one file to another file, refer to the following:
import java.io.*;
public class Copy {
public static void main(String[] args) throws IOException {
File inputFile = new File("file.txt");
File outputFile = new File("filecopy.txt");
FileReader in = new FileReader(inputFile);
FileWriter out = new FileWriter(outputFile);
int c;
while ((c = in.read()) != -1)
out.write(c);
in.close();
out.close();
}
}
if you want copy one file to another file, refer to the following:
import java.io.*;
public class Copy {
public static void main(String[] args) throws IOException {
File inputFile = new File("file.txt");
File outputFile = new File("filecopy.txt");
FileReader in = new FileReader(inputFile);
FileWriter out = new FileWriter(outputFile);
int c;
while ((c = in.read()) != -1)
out.write(c);
in.close();
out.close();
}
}