public class Fuzhi {
public static void main(String[] args) {
cope();
}
public static void cope() {
FileWriter fw = null;
FileReader fr = null;
try {
fw = new FileWriter("f:/dome-cope.txt");
fr = new FileReader("f:/dome.txt");
char[] buf = new char[1024];
System.out.println(new String(buf));
int len = 0;
while ((len = fr.read(buf)) != -1) {
fw.write(buf, 0, len);
}
} catch (IOException e) {
// TODO: handle exception
throw new RuntimeException("duxiecuowu");
} finally {
if (fr != null) {
try {
fr.close();
} catch (IOException e2) {
// TODO: handle exception
}
}
if (fw != null) {
try {
fw.close();
} catch (Exception e2) {
// TODO: handle exception
}
}
}
}
}
总是报错 求解!!!作者: 王梁星 时间: 2012-11-28 12:29
package test;
import java.io.*;
public class Fuzhi {
public static void main(String[] args) {
cope();
}
public static void cope() {
FileWriter fw = null;
FileReader fr = null;
try {
fw = new FileWriter("f:/dome-cope.txt");
fr = new FileReader("f:/dome.txt");
char[] buf = new char[1024];
System.out.println(new String(buf));
int len = 0;
while ((len = fr.read(buf)) != -1) {
fw.write(buf, 0, len);
}
} catch (IOException e) {
// TODO: handle exception
throw new RuntimeException("duxiecuowu");
} finally {
if (fr != null) {
try {
fr.close();
} catch (IOException e2) {
// TODO: handle exception
}
}
if (fw != null) {
try {
fw.close();
} catch (Exception e2) {
// TODO: handle exception
}
}
}
}
}
复制代码
报的什么错?是不是类似:
Exception in thread "main" java.lang.RuntimeException: duxiecuowu
at Fuzhi.cope(Fuzhi.java:23)
at Fuzhi.main(Fuzhi.java:7)
这个是读写错误,说明目录下没有源文件:dome.txt