我的家庭作业说“编写一个程序来读取一个文件并将文件的副本写入另一个插入了行号的文件”我有这个代码但是出了点问题,有人可以帮忙吗?先感谢您
显示文件:
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
class ShowFile {
public static void main(final String args[])
throws IOException
{
int i;
FileInputStream fin;
try {
fin = new FileInputStream(args[0]);
} catch (final FileNotFoundException e) {
System.out.println("File Not Found");
return;
} catch (final ArrayIndexOutOfBoundsException e) {
System.out.println("Usage: ShowFile File");
return;
}
do {
i = fin.read();
if (i != -1)
System.out.print((char) i);
} while (i != -1);
fin.close();
}
}
拷贝文件:
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
class CopyFile {
public static void main(final String args[])
throws IOException
{
int i;
FileInputStream fin;
FileOutputStream fout;
try {
// open input file
try {
fin = new FileInputStream(args[0]);
} catch (final FileNotFoundException e) {
System.out.println("Input File Not Found");
return;
}
// open output file
try {
fout = new FileOutputStream(args[1]);
} catch (final FileNotFoundException e) {
System.out.println("Error Opening Output File");
return;
}
} catch (final ArrayIndexOutOfBoundsException e) {
System.out.println("Usage: CopyFile From To");
return;
}
// Copy File
try {
do {
i = fin.read();
if (i != -1)
fout.write(i);
} while (i != -1);
} catch (final IOException e) {
System.out.println("File Error");
}
fin.close();
fout.close();
}
}
这是错误消息-
Exception in thread "main" java.lang.NoClassDefFoundError: C
Caused by: java.lang.ClassNotFoundException: C
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)