FileReader fr = new FileReader("ming.txt"); int ch = 0; while((ch = fr.read())!=-1 ) { System.out.print((char)ch); } |
while((ch = isr.read())!=-1) { System.out.print((char)ch); } |
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("ming.txt"))); String data = null; while((data = br.readLine())!=null) { System.out.println(data); } |
FileWriter fw = new FileWriter("hello.txt"); String s = "hello world"; fw.write(s,0,s.length()); fw.flush(); OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("hello2.txt")); osw.write(s,0,s.length()); osw.flush(); PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream("hello3.txt")),true); pw.println(s); |
import java.io.*; public class TestFile2 { public static void main(String[] args) throws IOException { FileReader fr = new FileReader("ming.txt"); char[] buffer = new char[1024]; int ch = 0; while((ch = fr.read())!=-1 ) { System.out.print((char)ch); } InputStreamReader isr = new InputStreamReader(new FileInputStream("ming.txt")); while((ch = isr.read())!=-1) { System.out.print((char)ch); } BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("ming.txt"))); String data = null; while((data = br.readLine())!=null) { System.out.println(data); } FileWriter fw = new FileWriter("hello.txt"); String s = "hello world"; fw.write(s,0,s.length()); fw.flush(); OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("hello2.txt")); osw.write(s,0,s.length()); osw.flush(); PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream("hello3.txt")),true); pw.println(s); fr.close(); isr.close(); br.close(); fw.close(); osw.close(); pw.close(); } } |