1. 程式人生 > >檔案流初識------筆記(len是int 型的怎麼和string使用的?有會的大佬可以回覆下謝謝)

檔案流初識------筆記(len是int 型的怎麼和string使用的?有會的大佬可以回覆下謝謝)

import java.io.*; public class newcollection {     public static void main(String args[])      {         File file=new File("D://1//WORLD.txt");//建立檔案物件         try         {             if(!file.exists()) //判斷檔案是否存在             {                 file.createNewFile();//不存在時新建             }             FileOutputStream out=new FileOutputStream(file);//定義FileOutputStream物件             byte buy[]="IO檔案流初次使用!".getBytes();             out.write(buy);//將buy位元組寫入流(寫入檔案)             out.close();         } catch (IOException e)         {             // TODO Auto-generated catch block             e.printStackTrace();         }         try         {             FileInputStream in=new FileInputStream(file);             byte a[]=new byte[1204];             //--------------------------------------------len的用處?int?string             int len=in.read(a);//從檔案中讀取資訊             System.out.println("IO流中的資料:"+new String(a,0,len));             in.close();                      } catch (IOException e)         {             // TODO Auto-generated catch block             e.printStackTrace();         }     } }