import java.io.*;
public class Outchant {
// 字節轉化成字符類型
public static void main(String[] args) {
// 異常處理
try {
fun();
fun1();
} catch (Exception e) {
e.printStackTrace();
}
}
// 字節轉化成字符類型
public static void fun() throws Exception{
// 創建要在那個文件中續寫文字
FileOutputStream fos=new FileOutputStream("d:\\IO\\ac.txt",true);
// 寫的格式為utf-8
OutputStreamWriter fow=new OutputStreamWriter(fos,"utf-8");
// 續寫的文字
fow.write("學的還行");
fow.close();
}
public static void fun1() throws Exception{
// 讀取文件中的文字
FileInputStream fis=new FileInputStream("d:\\IO\\ac.txt");
// 速度為1M
byte [] b=new byte[1024*10] ;
// 定義長度為0;
int len=0;
// 如果長度為-1結束運行
while((len=fis.read(b))!=-1){
// 打印
System.out.println(new String(b,0,len));
}
fis.close();
}
}