java中講講FileWriter的用法
FileWriter的用法
馬克- to-win:馬克 java社區(qū):防盜版實名手機尾號: 73203。
FileWriter是Writer的繼承類,從字面上就可看出,它的主要功能就是能向磁盤上寫文件。write方法會把字符一個一個的寫入磁盤中。
例:1.1.1
import java.io.*;
public class TestMark_to_win {
public static void main(String[] args) throws IOException {
File file = new File("c:\\test.txt");
FileWriter fw = new FileWriter(file);
/*void java.io.OutputStreamWriter.write(int c) throws IOException
Writes a single character.
Parameters:
c int specifying a character to be written*/
fw.write(97);
/*void java.io.Writer.write(String str) throws IOException
Writes a string.
Parameters:
str String to be written
*/
fw.write("this is 我們");
fw.close();
}
}
輸出的結果是:
athis is 我們