1.流的分類。輸入、輸出都是從程序運行所在內存的角度來劃分的。
2.字節流操作的最小數據單元是8位的字節,
字符流操作的最小數據單元是16位的字符。
3.使用FileInputStream讀取自身
public class FileInputStreamTest
{
public static void main(String[] args) throws IOException
{
//創建字節輸入流
FileInoutStream fis = new FileInputStream("FileInputSteaTest.java");
byte[] bbuf = new byte[1024];
int hasRead = 0;
while((hasRead = fis.read(bbuf)) > 0)
{
System.out.println(new String(bbuf,0,hasRead));
}
//關閉文件輸入流,放在finally塊裏更安全
fis.close();
}
}
4.使用FileReader讀取自身
public class FileReaderTest
{
public static void main(String[] args) throws IOException
{
FileReader fr = null;
try{
fr = new FileReader("FileReaderTest.java");
char[] cbuf = new char[32];
int hasRead = 0;
while((hasRead = fr.read(cbuf))>0)
{
System.out.println(new String(cbuf,0,hasRead));
}
}
catch(IOException ioe)
{
ioe.printStackTrace();
}
finally
{
if(fr != null)
{
fr.close();
}
}
}
}