Frage

I'm reading a txt with BuffererReader and I wonder how to give the path to my txt in BufferedReader's argument.

BufferedReader input = new Bufferedreader(
    new FileReader(D:VI.félév\Prog gyak\Project\proba.txt));

This doesn't seem to work.

War es hilfreich?

Lösung

Your problem is:

new Filereader( .. )

should be

new FileReader( .. )

And the path has to look like:

new FileReader("D:\\directory\\proba.txt");

You need an additional \ as escape character

Andere Tipps

Full Working Example with try..catch if problem any occur.

     BufferedReader br = null;

        try {

            String sCurrentLine;

            br = new BufferedReader(new FileReader("D:\\directory\\proba.txt"));

            while ((sCurrentLine = br.readLine()) != null) {
                System.out.println(sCurrentLine);
            }

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (br != null)br.close();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top