File fi = new File("c:\\ddd\\aa.txt");
fi.createNewFile();

解决方案 »

  1.   

    public String readFile(String filename) throws Exception 
       {
          //Read the file into a string buffer, then return as a string.
          StringBuffer buf;//the intermediary, mutable buffer
          BufferedReader breader;//reader for the template files
          try 
          {
             breader = new BufferedReader(new FileReader(filename));//header
             buf = new StringBuffer();
             while(breader.ready()) 
                buf.append((char)breader.read());
             breader.close();
          }//try
          catch(Exception e) 
          {
             throw e;
          }//catch
          return buf.toString();
       }//readFile   public static void writeFile(String str, String filename) throws Exception 
       {
          // Open a writer to the file, then write the string.
          BufferedWriter bwriter;//writer to the file
          String fullfilepath;//path for the output file
          try 
          {
             bwriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filename)));
             bwriter.write(str);
             bwriter.flush();
             bwriter.close();
          }//try
          catch(Exception e) 
          {
             throw e;
          }//catch
       }//writeFile
      

  2.   

    PrintWriter out=new PrintWriter(new FileOutputStream("d:\\myfile.txt"));
    out.println("hello world");
    ou.close();//创建完成BufferedReader in=new BufferedReader(new InputStreamReader(new FileInputStream("d:\\myfile.txt")));
    System.out.println(in.readLine());//读取
    in.close();//关闭
      

  3.   

    创建
    File txtFile = new File("c:\\temp\\","a.txt");
    try {
      txtFile.createNewFile();
    }catch(IOException e ){}
    读取
    FileInputStream in = new FileInputStream (txtFile);
    try{
       byte b=0;
       while( (b=in.read()>=0)  {
              。
       }
    }catch(IOException e ){}