Read File

How I can read a file in macosX, something is wrong here but what?

For example, I will read a.html with a java file but something is wrong with relative pathnames?

If I give in terminal: java filenameIN a.html

an error appears.

// here the error message in terminal

xception in thread "main" java.lang.NoClassDefFoundError: LiesDateiEin/java
Caused by: java.lang.ClassNotFoundException:
      at Method)
      at java.lang.ClassLoader.loadClass(
      at sun.misc.Launcher$AppClassLoader.loadClass(
      at java.lang.ClassLoader.loadClass(
      at java.lang.ClassLoader.loadClassInternal(

public class LiesDateiEin {

     * @param args the command line arguments
    public static void main(String[] args) {
        // Dateiname wir übergeben

        String filenameIn = args [0];

        try {

             FileInputStream fis = new FileInputStream (filenameIn);
             InputStreamReader isr = new InputStreamReader(fis);
             BufferedReader bur = new BufferedReader (isr);

             // die erste Zeile wird eingelesen

             String sLine = bur.readLine();

             // lies alle Zeilen aus, bis keine mehr vorhanden sind
             // und gib sie nacheinander aus
             //falls von vornherein nichts in der Datei enthalten
             // ist, wird dieser Prorammabschiniit übersprungen

             int zaehler = 0;

             while (sLine !=null){
                 System.out.println ("Zeile"+zaehler+":"+sLine);
                 sLine = bur.readLine();
             // schliess die Datei

        }catch (IOException eIO){
            System.out.println ("folgender Fehler trat auf: "+eIO);



Open in new window

Who is Participating?
The issue is not with it being unable to find a.html but it is unable to execute LiesDateiEin

What directory are you typing the command from?

Should'nt the command be - java  LiesDateiEin a.html
add . to your classpath. This means adding current directory to your classpath
Does your source code file have the name You have to have the same name on the file as the class.
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Element_TAuthor Commented:
oh sorry, my fault, you are right...

Also you need to execute like below

java LiesDateiEiN a.html

In this case a. Html should be in current directory as per program
Element_TAuthor Commented:
my fault, it was because the prefix .java.

I used tab and its includes the prefix, but the command java works without prefix.

java LiesDateiEin a.html is working...
Element_TAuthor Commented:
It was my fault.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.