我需要java方面的帮助
在代码中,我从输入文件中读取信息并将其写入输出文件。在输入文件中,我有以下信息1245:我的地址:佛罗里达州迈阿密
然后,当信息写入输出时,我需要它来更改:for |。谁能解释一下我该怎么做
import java.io.*;
public class fileConverted {
public static void main(String args[]) {
try {
File input = new File("input");
File output = new File("output");
Scanner sc = new Scanner(input);
PrintWriter printer = new PrintWriter(output);
while (sc.hasNextLine()) {
String s = sc.nextLine();
printer.write(s);
}
printer.flush();
}
catch (FileNotFoundException e) {
System.err.println("File not found. Please scan in new file.");
}
}
}
# 1 楼答案
请试试这个,它很好用
# 2 楼答案
# 3 楼答案
在写入输出文件之前调用字符串。replaceAll()方法
# 4 楼答案
添加以下行:
之后