会读怎么就不会写呢?
其实是一样的,不就是吧Reader改为Writer吗?

解决方案 »

  1.   

    FileWriter fOut = null;
                    try 
                    {
                        fOut = new FileWriter(file);
                        String fileContent = "文件内容";
                        fOut.write(fileContent);   
                        fOut.close();
                        fOut = null;
                    } 
                    catch (FileNotFoundException e1) 
                    {
                        e1.printStackTrace();
                    }
                    catch(IOException eIO)
                    {
                        eIO.printStackTrace();
                    }                
                    finally
                    {
                        if (null != fOut)
                        {
                            try {
                                fOut.close();
                            } catch (IOException e2) {
                                // TODO Auto-generated catch block
                                e2.printStackTrace();
                            }
                        }
                    }
      

  2.   

    import java.io.*;
    import java.util.*;class p2 
    {
    public static void main(String[] args) 
    {
    try
    {
    BufferedReader br=new BufferedReader(new InputStreamReader(new FileInputStream("p1.java")));
    DataOutputStream dos=new DataOutputStream(new FileOutputStream("pp.java"));
    String str;Object o;
    //while(br.ready())
    while((str=br.readLine())!=null)
    {

    l.add(str);
    //System.out.println(str);
    }
    //ListIterator it=l.listIterator();
    int i=1;
    while ((o=l.removeLast())!=null)
    {
    System.out.println((String)o);
    dos.writeBytes(i+" "+(String)o+"\n");
    i++;
    }

    while(it.hasNext())
    {
    System.out.println((String)it.next());
    }
    while(it.hasPrevious())
    {
    System.out.println((String)it.previous());
    }
    */
    //System.out.println("Hello World!");
    }
    catch (Exception e)
    {
    } }
    }