Filreader with a string

34 views Asked by At

This is my code:

public static void NameLaden() throws IOException {
    File f = new File(path1);
    FileReader g;
    g = new FileReader(f);
    Name = g.read();                
    g.close();      
}

The answer is probably really simple. The only problem I have is that he wants a int instead of a string for Name. But Name has to be a string since its a word.

1

There are 1 answers

0
NaN On BEST ANSWER

Try it like this. Did not test it, but it should work, if name is on the first line of the file.

public static void NameLaden() throws IOException {
    File f = new File(path1);

    FileReader g = new FileReader(f);
    BufferedReader br = new BufferedReader(g);
    String Name = br.readLine();
    br.close();   
    g.close();      
}