天天看點

java檔案流輸出_java檔案讀寫(輸入輸出流)

package filetest;

import java.io.*;

public class FileTest {

public static void main(String[] args) {

// TODO code application logic here

try

{

//簡單寫檔案,除此以外,還有RandomAccessFile

BufferedWriter writer = new BufferedWriter(new FileWriter("testdata.txt"));

String line = "hello world!";

writer.write(line);

writer.flush();

writer.close();

}

catch(IOException e)

{

System.out.println("file read error!");

}

}

}

java檔案流輸出_java檔案讀寫(輸入輸出流)