看板 b94902HW 關於我們 聯絡資訊
※ 引述《luyota (吉他手)》之銘言: : 有哪位強者講一下方法吧=w= : 包括開檔讀檔還有少耗空間的方法 : 感恩~ 如果是文字檔的話,可以試試以下的方法, 或者用用java.util.Scanner 大概常用開檔就這兩個. (需import java.io.*;) try{ BufferedReader input=new BufferedReader(new FileReader("input.txt")); while(input.ready()){ System.out.println(input.readLine()); //一次讀一行 //input.read() 一次讀一個字元 :P } input.close(); }catch(IOException e){ System.out.println("FileNotFound Exception"); } 少耗空間的話,利用Buffer區的概念作吧... 簡單來講就是把Buffer區縮小而已 需要用到的時候再去讀它 寫文字檔 (一樣要 import java.io.*;) try{ FileWriter fw=new FileWriter("out.txt"); fw.write("我是第一行\r\n"); fw.write("我是第二行\r\n"); fw.close(); //關閉串流並把write的內容丟進檔案內 }catch(IOException e){ System.out.println("CanNotWriteFile Exception"); } 如果需要把資料累加在原檔後面而不是覆寫的話, 建構子加個true就行了。:) FileWriter fw=new FileWriter("out.txt",true); Best wishes, -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.138.240.58 ※ 編輯: TonyQ 來自: 140.138.240.58 (04/06 01:05)
TonyQ:ㄟˊ 好像有人的推文被我修掉了 不好意思啦 XD 04/06 01:05
LPH66:我的推文@@ 話說我們的資料是binary的... 04/06 10:52
TonyQ:那就用 InputStreamReader吧Y 04/06 23:10