package 练习12号;
import java.io.*;
public class FileStream {
public static void main(String[] args) throws IOException{
readFile2();
}
public static void writeFile() throws IOException{
FileOutputStream fw=new FileOutputStream("zxn.txt");
fw.write("abcdefg".getBytes());
}
public static void readFile() throws IOException{
FileInputStream fr=new FileInputStream("zxn.txt");
int ch;
while((ch=fr.read())!=-1){
System.out.println((char)ch);
}
}
public static void readFile2() throws IOException{
FileInputStream fr2=new FileInputStream("zxn.txt");
int len=0;
byte[] buf=new byte[1024];
while((len=fr2.read(buf))!=-1){
System.out.println(new String(buf,0,len));
}
fr2.close();
}
}
输出结果:
abcdefg