OutputStream os=new FileOutputStream("C:\\myTxt.txt"));
PrintWriter pw=new PrintWriter(os);
pw.println("hello");
pw.println("world");
pw.close();

解决方案 »

  1.   

    不好意思,文件名你改为hello.txt就是你要的了:)
      

  2.   

    import java.io.*;public class test{
    public static void main(String [] args){
    try{
         FileOutputStream fout = new FileOutputStream("c:\\test.txt");
         String s = "hello\nworld";
        fout.write(s.getBytes());
    fout.close();
    }catch(Exception e){
    }
    }
    }
      

  3.   

    String pathname="C:\My Documents\hello.txt";
    File f= new File(pathname);
    f.createNewFile();
    FileWriter  fo=new FileWriter(file);
    FileWriter.write("hello");
    FileWriter.write("world");
      

  4.   

    对不起,没看清,原来你又用了PrintWriter
      

  5.   

    除了PrintWriter,还可以用PrintStream
      

  6.   

    哈哈,简单的问题就看谁抢得快啦,别忘了加上
    import java.io.*;
      

  7.   

    CFile file1("C:\\myTxt.txt",CFile::modeWrite|CFile::modeNoTruncate|CFile::modeCreate);
    file1.SeekToEnd();
    file1.Write("hello",strlen("hello"));
    file1.Write("\r\n",strlen("\r\n"));
    file1.Write("world",strlen("world"));
    file1.Close();