java中講講PrintWriter的用法

PrintWriter的用法
馬克-to-win:PrintWriter和PrintStream類似,只不過PrintStream是針對字節(jié)流的,而PrintWriter是針對字符流的。
馬克- to-win:馬克 java社區(qū):防盜版實名手機尾號: 73203。



例:1.2.1
import java.io.*;
public class TestMark_to_win {
    public static void main(String args[]) throws Exception {
        String s1 = "我們" + "\n";
        String s2 = "你們" + "\n";
        PrintWriter p = new PrintWriter("c:/out.txt");
        p.println("output" + s1);
        p.println("output" + s2);
        /*without using the following statement, the file name can be write out, but the content of the file is empty. */
        p.close();
    }
}


結(jié)果是:

output我們

output你們