1读写字符文件
BufferedReader br=new BufferedReader(new FileReader("文件路径"));
BufferedWriter bw=new BufferedWriter(new FileWriter("文件路径",boolean));
public static void main (String[] args) throws Exception{ BufferedWriter bw=new BufferedWriter(new FileWriter("src/a.txt"); BufferedReader br=new BufferedReader(new FileReader("src/d.txt")); String str=null; while((str=br.readLine())!=-1){ System.out.println(str); } bw.close(); br.close(); } |
2读写字节文件
DataInputStream dis=new DataInputStream(new FileInputStream("文件路径"));
DataOutputStream dos=new DataOutputStream(new FileOutputStream("文件路径"));
public static void main(String[] args) throws Exception { |
3读取整个字符文件
String str=null;
while((str=br.readLine())!=-1){
System.out.println(str);
}
4读取整个字节文件
int b;
while((b=dis.read())!=-1){
System.out.println(b);
}