1. 程式人生 > >黑馬程式設計師——基礎知識--IO流

黑馬程式設計師——基礎知識--IO流

import java.io.*; public class Test { public static void main(String[] args) { try { String content = "Thank you for your fish."; File file = new File("new.txt"); // create the file if doesn't exists if (!file.exists()) { file.createNewFile(); } FileWriter fw
= new FileWriter(file.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); bw.write(content); bw.close(); } catch(IOException e) { System.out.println("IO Problem"); } } }