java io流
創建文件
寫入數據
改變system.out.print的輸出位置
//創建文件 //寫入數據 //改變system.out.print的輸出位置 import java.io.*; public class Index{ public static void main(String[] args) throws Exception{ /** * 存儲為二進制,給計算機看的 */ //創建文件 DataOutputStream sjl = new DataOutputStream(new FileOutputStream("D:/1.txt")); //寫入數據 sjl.writeLong(123456); //關閉文件 sjl.close(); /** * 存儲為,給用戶看的 */ //創建文件 PrintStream pl = new PrintStream(new FileOutputStream("D:/2.txt")); //寫入數據 pl.println(123456); //關閉文件 pl.close(); /** * 設置輸出位置 * 改變system.out.print 的尋常輸出位置,使它輸出到文件 */ //創建文件 PrintStream pl_2 = new PrintStream(new FileOutputStream("D:/3.txt")); //設置輸出到什么位置,改變輸出位置 System.setOut(pl_2); System.out.print("大家好"); //關閉文件 pl_2.close(); } }