我的家庭作業說「寫一個讀取文件的程序,並將該文件的一個副本寫入另一個帶有行號的文件」我有這段代碼,但是出了什麼問題,有誰能幫忙嗎?謝謝你在前進這段代碼有什麼問題
演出文件:
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();
}
}
的CopyFile:
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();
}
}
這是錯誤MESSAGE-
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)
什麼是錯誤訊息? – Patashu 2013-03-18 03:03:27
而問題會是? – MadProgrammer 2013-03-18 03:07:26
@Slink保持簡單,您可以嘗試下面給出的代碼。 – 2013-03-18 03:15:22