檔案讀寫

ahesihua發表於2011-10-11

之前對用java語言實現從檔案讀資料 和將資料寫入到檔案一直很畏懼,現在實現了一個簡單的寫一行資料到檔案和從檔案中讀資料出來

	public static void main(String[] args) throws IOException {
		File file=new File("F:/chatBotsProject/testReplace/fileinput/input.txt");
		BufferedWriter out=new BufferedWriter(new FileWriter(file));
		out.write("test writer some words to file");
		out.close();		
		
		BufferedReader reader=new BufferedReader(new FileReader(file));
		String line="";
		
		while(reader.ready())
			line=reader.readLine();
		
		reader.close();
		System.out.println(line);
		System.out.println("test success.");
	}