首先编译的时候应该是这样 javac NoteBook.java
然后运行才是:java old.txt new.txt
还有个问题就是,如果你想把old.txt的内容写到new.txt里那么你的读和写就搞反了

解决方案 »

  1.   

    错,dlglmf(雨魂)也被snage (霹雳狂刀)弄糊涂了,怎么运行的?snage (霹雳狂刀) 现在还不会运行吗?看扫盲帖吧.设好classpath后:java com.snage.io.NoteBook old.txt new.txt
      

  2.   

    你的程序有点错误,偶试着改了一下,千万记得
    不能用 == 比较 String 的值偶试了一下 java NoteBook NoteBook.java NoteBook.java.bak 可以运行成功
    import java.io.*;
    public class NoteBook {
    private File newFile;
    private File oldFile;
    private BufferedReader reader;
    public String content;
    private PrintWriter writer;
    public void readContent(String str) throws IOException{
    content="";
    newFile = new File(str);
    try{
    reader = new BufferedReader(new FileReader(newFile));
    String str1 = null;
    while((str1 = reader.readLine() )!= null)
    content += str1 + "\n";
    reader.close();
    }
    catch(IOException e){
    System.out.println(e);
    }

    }
    public void writeContent(String str) throws IOException{
    oldFile=new File(str);
    try{
    writer = new PrintWriter(new BufferedWriter(new FileWriter(oldFile)));
    writer.println(content);
    writer.close();
    }
    catch(IOException e){
    System.out.println(e);
    }
    } public static void main(String[] args) throws IOException{
    NoteBook book=new NoteBook();
    book.readContent(args[0]);
    book.writeContent(args[1]);

    }
    }
      

  3.   

    我又重改了一下:
    package com.snage.io;
    import java.io.*;/**
     * @author TSG129
     *
     * TODO To change the template for this generated type comment go to
     * Window - Preferences - Java - Code Style - Code Templates
     */
    public class Books { public static void main(String[] args) throws IOException {
    File newFile=new File("d:/new.txt");
    File oldFile=new File("d:/old.txt");
    String s;
    BufferedReader reader=new BufferedReader(new FileReader("d:/old.txt"));
    PrintWriter writer=new PrintWriter(new BufferedWriter(new FileWriter("d:/new.txt")));
    while((s=reader.readLine())!=null)
    writer.println(s);
    reader.close();
    writer.close();

    }
    }