BufferReader
程序是想读取文件,生成一个不含指定字符的文件,然后将新文件复制到源文件上,为什么一运行,源文件的内容就变成空了?
package FileAndDir;
import java.io.*;
import java.nio.Buffer;
public class CopyDelete {
public static void main(String[] args) {
// TODO Auto-generated method stub
File file = new File("..\\Text\\Output.txt");
try {
BufferedReader inFile = new BufferedReader(new FileReader(file));
BufferedWriter outFile = new BufferedWriter(new FileWriter(file));
String s = "";
while ((s = inFile.readLine()) != null) {
if (!s.contains("public")) {
outFile.write(s);
outFile.flush();
}else{
s.replaceAll("public", "");
outFile.write(s);
outFile.flush();
}
}
} catch (
FileNotFoundException ex) {
ex.printStackTrace();
} catch (
IOException ex) {
ex.printStackTrace();
}
}
}
请高手指教!!
------解决方案--------------------
为什么对应同一个文件。。。逻辑不通吧
你写出文件换一个