首先编译的时候应该是这样 javac NoteBook.java
然后运行才是:java old.txt new.txt
还有个问题就是,如果你想把old.txt的内容写到new.txt里那么你的读和写就搞反了
然后运行才是:java old.txt new.txt
还有个问题就是,如果你想把old.txt的内容写到new.txt里那么你的读和写就搞反了
解决方案 »
- 求代码
- 关于ThreadLocal的诡异问题,百思不得其解
- 如何实现JTextArea的大小自动随窗口大小的变化而变化
- 给定一个java.util.Date对象,如何转化为"2007-3-22 20:23:22"
- 连接mysql的时候报错Access denied for user: '[email protected]' (Using password: YES)
- 请帮忙,这个题目如何解答?
- 谢谢一个 简单的问题 语法上的??
- try语句块中的return和finally中的try语句返回的结果存放在内存的哦什么地方
- 两个及其简单的问题,一定给分
- jdbc的中文问题!
- 怎么样在JBUilder9 中配置新下载的Java Sound api,和JMF啊?
- help 一个线程问题
不能用 == 比较 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]);
}
}
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();
}
}