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();
}
}
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();
}
}
相关文章推荐
- nodejs 读取JSON文件写入txt中 fs.readFile&fs.writeFile
- 并发库应用之五 & ReadWriteLock场景应用
- unix/Linux 低级IO函数的用法read && write
- ReentrantReadWriteLock & ReentrantLock & Synchronized 区别
- Perl I/O Read & Write
- SVN无法提交 Can't set file "/db/txn_current" read-write :拒绝访问
- write&read&open
- Write operations are not allowed in read-only mode (FlushMode.NEVER) - turn your Session into FlushMode.AUTO or remove 'readOnly
- @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE, region = "entityCache")
- Write operations are not allowed in read-only mode (FlushMode.NEVER) - turn your Session into FlushMode.AUTO or remove 'readOnly
- Only Read & Write World - Rex Wang
- read/write&mmap&aio
- <Win32 API> 文件操作CreateFile/ReadFile/WriteFile
- IniFile read & write source code
- Write operations are not allowed in read-only mode (FlushMode.NEVER) - turn your Session into FlushMode.AUTO or remove 'readOnly
- PESSIMISTIC_READ & PESSIMISTIC_WRITE 与 共享锁 & 排它锁
- mongoDB——read&write操作
- read/write&mmap&aio
- copy on read & copy on write
- Java Concurrency - ReadWriteLock & ReentrantReadWriteLock