日期:2014-05-20 浏览次数:20728 次
File org = new File("test.txt"); File bak = new File("test.txt.bak"); BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(org))); PrintStream ps = new PrintStream(new FileOutputStream(bak)); String buf = null; while ((buf=br.readLine()) != null) { //add, modify, delete, so on, ps.println(buf); } br.close(); ps.close(); org.delete(); if (! org.exists()) { bak.renameTo(org); }
------解决方案--------------------
读取指定行
http://blog.csdn.net/yaowenqian99/article/details/5403694
------解决方案--------------------
http://www.cnblogs.com/rollenholt/archive/2011/09/11/2173787.html
------解决方案--------------------
import java.io.*;
public class Lian {
public static void main(String [] args) throws IOException {
File org = new File("c:/old.txt");
File bak = new File("c:/new.txt");
org.createNewFile();
bak.createNewFile();
InputStreamReader in= new InputStreamReader(new FileInputStream(org));
BufferedReader br = new BufferedReader(in);
PrintStream ps = new PrintStream(new FileOutputStream(bak));
String buf = null;
while ((buf=br.readLine()) != null) {
ps.println(buf);
}
br.close();
ps.close();
org.delete();
if (! org.exists()) {
bak.renameTo(org);
}
}
}
------解决方案--------------------
http://www.cnblogs.com/rollenholt/archive/2011/09/11/2173787.html这个很详细,希望能帮到楼主