import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class IOTest {
public static void main(String[] args){
File f = new File("E:\\1.txt");
//读
String oldStr = "";
try {
FileReader fr = new FileReader(f);
BufferedReader br = new BufferedReader(fr);
String line = null;
while((line = br.readLine())!=null){
oldStr += line;
}
} catch (FileNotFoundException e1) {
e1.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
//写
String newStr = "zxc";
FileWriter fw;
try {
fw = new FileWriter(f);
BufferedWriter bw = new BufferedWriter(fw);
bw.write(oldStr+"\r\n"+newStr);//不想换行就把\r\n去掉
bw.close();
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class IOTest {
public static void main(String[] args){
File f = new File("E:\\1.txt");
//读
String oldStr = "";
try {
FileReader fr = new FileReader(f);
BufferedReader br = new BufferedReader(fr);
String line = null;
while((line = br.readLine())!=null){
oldStr += line;
}
} catch (FileNotFoundException e1) {
e1.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
//写
String newStr = "zxc";
FileWriter fw;
try {
fw = new FileWriter(f);
BufferedWriter bw = new BufferedWriter(fw);
bw.write(oldStr+"\r\n"+newStr);//不想换行就把\r\n去掉
bw.close();
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}