Java 程式設計 -- 檔案
Java 程式簡介運算式分枝迴圈陣列函數遞迴錯誤處理物件導向封裝繼承多型技巧函式庫字串數學正規表達式容器檔案網路資料庫視窗ThreadListener錯誤陷阱相關檔案相關資源教學錄影Eclipse考題解答訊息相關網站參考文獻最新修改簡體版English |
範例:整數輸出import java.io.*; public class OutputStream1 { public static void main(String[] args) throws Exception { DataOutputStream out = new DataOutputStream(new FileOutputStream("OutputStream.dat")); for (int i=0; i<10; i++) out.writeInt(i); out.close(); } } 範例:文字檔複製import java.io.*; public class IO1 { public static void main(String args[]) throws Exception { FileReader reader = new FileReader("InTest.txt"); char[] data = new char[1024]; int num = reader.read(data); String text = new String(data, 0, num); System.out.println(text); reader.close(); FileWriter writer = new FileWriter("OutTest.txt"); writer.write(text); writer.close(); } } |
page revision: 1, last edited: 04 Nov 2010 03:37
Post preview:
Close preview