[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 336
  • Last Modified:

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

0
Element_T
Asked:
Element_T
2 Solutions
 
arevuriCommented:
add . to your classpath. This means adding current directory to your classpath
0
 
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
 
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now