您的位置:首页 > 其它

Read&WriteTXT

2014-05-17 14:03 246 查看
package ReadTXT;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.*;

public class Filedo {
//逐行写入文本
public static void main(String[] args) throws IOException{
String filePath = "Data//test.txt";
readFile(filePath);
//writeFile(filePath);
}

public static final void writeFile(String str) throws IOException {
String filePath = "Data//output.txt";
FileWriter fw = null;
try {
fw = new FileWriter(filePath,true);
//String c = "abs"+"\r\n";
fw.write(str);
fw.close();
//fw.flush();
//readF1(filePath);
} catch (IOException e1) {
e1.printStackTrace();
System.out.println("写入失败");
System.exit(-1);
}
}

//逐行读取文本
public static final void readFile(String filePath) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(
new FileInputStream(filePath)));
for (String line = br.readLine(); line != null; line = br.readLine()) {
//System.out.println(line);
if(!line.startsWith("A")){
writeFile(line);
System.out.println(line);
}
}
br.close();
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: