import java.io.*; import java.util.Scanner; public class FileIOBufferedOutputStream { public static void main(String[] args) { try { String fileName, fileDir; System.out.println("請輸入檔名: "); Scanner sn = new Scanner(System.in); fileDir = sn.next(); BufferedOutputStream of = new BufferedOutputStream(new FileOutputStream(fileDir)); String str = "Hello World!"; byte[] b = str.getBytes(); for(int i = 0; i < b.length; i++) of.write(b[i]); of.close(); } catch(IOException e){ System.out.println("輸入檔案路徑錯誤"); } } }執行結果
新增檔案