0

i am wondering what is the problem here.
here text.txt is the input file.
any help will be highly appreciated.

import java.io.*;


  
public class Main{
public static void main(String[] args) throws Exception
{
 File f= new File("text.txt");
BufferedReader in = new BufferedReader(
		   new FileReader(f));
String line = new String(); 
line  = in.readLine();
while(line!=null){
System.out.println(line);
line = in.readLine();
}
}
}

this is what compiler shows
parth@ubuntu:~/Desktop$ javac Main.java
parth@ubuntu:~/Desktop$ java Main.java
Exception in thread "main" java.lang.NoClassDefFoundError: Main.java
at gnu.java.lang.MainThread.run(libgcj.so.11)
Caused by: java.lang.ClassNotFoundException: Main.java not found in gnu.gcj.runtime.SystemClassLoader{urls=[file:./], parent=gnu.gcj.runtime.ExtensionClassLoader{urls=[], parent=null}}
at java.net.URLClassLoader.findClass(libgcj.so.11)
at gnu.gcj.runtime.SystemClassLoader.findClass(libgcj.so.11)
at java.lang.ClassLoader.loadClass(libgcj.so.11)
at java.lang.ClassLoader.loadClass(libgcj.so.11)
at gnu.java.lang.MainThread.run(libgcj.so.11)

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by NormR1
0

The java command takes the name of a class for its argument. You have give it the filename of the source file.
The class name is the name of the class not the name of the file. There is no .class in a class name.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.