展开全部
有简单的方法,给你个例子32313133353236313431303231363533e59b9ee7ad9431333332626633import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.Writer;
import java.util.Scanner;
public class Test {
public static void main(String args[]) {
String srcFile = "D:/a.txt";
String toFile = "D:/b.txt";
try {
String result = read(srcFile);
write(result, toFile);
} catch (Exception e) {
e.printStackTrace();
}
}
private static String read(String srcFile) throws FileNotFoundException {
Scanner in = new Scanner(new File(srcFile));
String result = "";
while (in.hasNextLine()) {
result += in.nextLine() + "\r\n";
}
in.close();
return result;
}
private static void write(String result, String toFile) throws Exception {
Writer w = new FileWriter(new File(toFile));
w.write(result);
w.flush();
w.close();
}
}