Reading from .txt

Discussion in 'Plugin Development' started by kaZep, Oct 30, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    kaZep

    Hello, since i started to learn java, i had a question which was "how to read from .txt file". I looked over a lot of tutorials, but i learned to to write in a txt file... Now i'm having a lot of troubles with this thing. I know it's very hard and yes, i don't want dirrectly the code. Just some hints, or some help when i'm getting errors. Thanks for your time :)
     
  2. Offline

    raGan.

  3. Offline

    kaZep

    I made a bit, it's like

    PHP:
        public void readFromCmds(){
            
    Path file "test.txt";
            try (
    InputStream in Files.newInputStream(file);
                
    BufferedReader reader =
                  new 
    BufferedReader(new InputStreamReader(in))) {
                
    String line null;
                while ((
    line reader.readLine()) != null) {
                    
    System.out.println(line);
                }
            } catch (
    IOException x) {
                
    System.err.println(x);
            }
        }
    but i'm getting an error from

    PHP:
            Path file "test.txt";
    What is it telling me

    Code:
    Type mismatch: cannot convert from String to Path
     
  4. Offline

    tbsman

    You cannot convert from String to Path, try doing:
    Code:
    String file = "test.txt"
     
  5. Offline

    raGan.

  6. Offline

    kaZep

    Ok i did it like

    PHP:
        public void readFromCmds(){
            
    Path file Paths.get("test.txt");
            try (
    InputStream in Files.newInputStream(file);
                
    BufferedReader reader =
                  new 
    BufferedReader(new InputStreamReader(in))) {
                
    String line null;
                while ((
    line reader.readLine()) != null) {
                    
    System.out.println(line);
                }
            } catch (
    IOException x) {
                
    System.err.println(x);
            }
        }
     
Thread Status:
Not open for further replies.

Share This Page