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: LiesDateiEin.java
      at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:315)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:330)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:250)
      at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:398)

import java.io.*;
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();
                 zaehler++;
             }
             // schliess die Datei
             bur.close();

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



    }

}

Open in new window

Element_TAsked:
Who is Participating?
 
a_bCommented:
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
0
 
arevuriCommented:
add . to your classpath. This means adding current directory to your classpath
0
 
nordtorpCommented:
Does your source code file have the name LiesDateiEin.java? You have to have the same name on the file as the class.
0
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...


0
 
arevuriCommented:
Also you need to execute like below

java LiesDateiEiN a.html

In this case a. Html should be in current directory as per program
0
 
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...
0
 
Element_TAuthor Commented:
It was my fault.
0
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.