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

2012/5/29

Reading a File

1
2
DonaldDuck DonaldDuck

2012/6/15

#
Yes, exactly danpost. The variable maxLevel can be replaced by the last line number of your document to make it read the entire document. In this way, the string array it returns will be ordered in such a way that String returned from readText() will be the first line of the document, etc. until the maxLevel (last line of the document)
darkmist255 darkmist255

2012/6/15

#
I assumed that this was the use for maxLevel, wasn't sure what I should be setting it at. Is there a method to get the length in lines of a file by chance? I'm new to file reading classes, gonna try to learn the ins and outs.
DonaldDuck DonaldDuck

2012/6/17

#
I believe (but am not sure) that you can just say: String s; while((s = r.readLine()) != null) { System.out.println(s); } and this will output the contents of every line... Again, I'm not sure.
kiarocks kiarocks

2012/6/17

#
That works fine!
kiarocks kiarocks

2012/6/17

#
FileInputStream fstream = new FileInputStream("file.txt");
                            // Get the object of DataInputStream
                            DataInputStream in = new DataInputStream(fstream);
                            BufferedReader br = new BufferedReader(new InputStreamReader(in));
                            String strLine;
                            //Read File Line By Line
                            while ((strLine = br.readLine()) != null)   {
                                // Print the content on the console

                                System.out.println(strLine);

                                }
                            }
This code is more detailed.
darkmist255 darkmist255

2012/6/18

#
Thanks, I'll give that a shot, seems logical.
PHORNE31 PHORNE31

2012/6/25

#
Thanks, I'll give it a try.
You need to login to post a reply.
1
2