This site requires JavaScript, please enable it in your browser!
Greenfoot back
divinity
divinity wrote ...

2017/6/3

bufferedreader not reading the file

divinity divinity

2017/6/3

#
hi danpost i am doing this java program about a hospital that require a guie but the administrative class has to be connected to the GUI and it also require that it read a file that contain all of the administrative staff of the hospital, doctor, dermatologist, cardiologist, student, full-time job, part time job, exchange students, the visa, courses and GPA. the problem that I am having is getting the program to read the file. i am using the burreredreader, inputstreamread and filereader but for some reason am not getting the bufferedreader to read the file, it is giving me an error that says, it cannot find symbol and to create a field in the administrative class can you tell me what i am doing wrong. I have put the file exactly where it supposed to be in order for it to read the file. here is the codes that i am using:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
       FileReader fr = null;
        
       try{
          fr = new FileReader(txtarea.txt);
           br = new BufferedReader(fr);
            
           String rCurrentLine;
          br = new BufferedReader(new FileReader(txtarea.txt));
            
           while((rCurrentLine = br.readLine()) !=null){
               System.out.println(txtarea.txt);
           }
            
            
       }catch(IOException e){
       }      
        
   }
danpost danpost

2017/6/3

#
divinity wrote...
it is giving me an error that says, it cannot find symbol and to create a field in the administrative class
What symbol does it say it cannot find and what line does it point to?
divinity divinity

2017/6/4

#
that will be line 5, line 9 an line 12. the txtarea.txt, that is the error am getting
danpost danpost

2017/6/4

#
If 'textarea.txt' is a filename, you need to put it within double quotes. Change line 5 to:
1
FileReader fr = new FileReader("textarea.txt");
You only need to create one FileReader object for the file, so change line 9 to:
1
br = new BufferedReader(fr);
You only need to create one BufferedReader, so change line 1 to:
1
BufferedReader br = null;
Finally, line 12 should probably be printing the lines read in from the file, so change line 12 to:
1
System.out.println(rCurrentLine);
Also, the file should be closed when all lines have been read.
divinity divinity

2017/6/4

#
Thank u Dan post and now my laptop like it gone thru jumble ting boi
divinity divinity

2017/6/5

#
hi danpost thank you very much got it to read the file
You need to login to post a reply.