Read File

Posted on 2009-12-26
Last Modified: 2013-11-23
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

Question by:Element_T
    LVL 6

    Expert Comment

    add . to your classpath. This means adding current directory to your classpath
    LVL 20

    Accepted Solution

    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
    LVL 11

    Expert Comment

    Does your source code file have the name You have to have the same name on the file as the class.

    Author Comment

    oh sorry, my fault, you are right...

    LVL 6

    Assisted Solution

    Also you need to execute like below

    java LiesDateiEiN a.html

    In this case a. Html should be in current directory as per program

    Author Comment

    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...

    Author Closing Comment

    It was my fault.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
    Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
    Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
    Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now