Results 1 to 4 of 4
Thread: list
- 11-19-2007, 02:48 AM #1
Member
- Join Date
- Nov 2007
- Posts
- 14
- Rep Power
- 0
- 11-19-2007, 08:36 PM #2
readingAFile.txtJava Code:import java.io.*; public class ReadingAFile { public static void main(String[] args) { String[] strs = new String[20]; int count = 0; BufferedReader br = null; try { File file = new File("readingAFile.txt"); br = new BufferedReader( new InputStreamReader( new FileInputStream(file))); String line; while((line = br.readLine()) != null) { strs[count++] = line; } br.close(); } catch(IOException e) { System.out.println("read error: " + e.getMessage()); } for(int j = 0; j < count; j++) { System.out.println(strs[j]); } } }
Java Code:Waking Ned Devine No Country for Old Men The Postman Clearcut The Princess Bride
- 11-20-2007, 05:06 AM #3
Member
- Join Date
- Nov 2007
- Posts
- 14
- Rep Power
- 0
thank you man but it doesnt print out why? should it be something like j< count.length :confused: ?
- 11-20-2007, 07:22 AM #4
The value of the int variable "count" increases every time another line is read so its final value should be the number of non–null elements in the "strs" array.
Try this:
to see what is happening inside the while loop.Java Code:while((line = br.readLine()) != null) { strs[count++] = line; System.out.println("count = " + count + " line = " + line); }
Similar Threads
-
Members List
By Eranga in forum Suggestions & FeedbackReplies: 11Last Post: 01-17-2008, 10:41 AM -
To display as a list
By yuvi461 in forum New To JavaReplies: 2Last Post: 01-09-2008, 12:06 PM -
Linked List
By rnavarro9 in forum New To JavaReplies: 0Last Post: 11-29-2007, 03:42 AM -
Link List
By one198 in forum New To JavaReplies: 0Last Post: 10-14-2007, 01:33 PM -
How to get the max value from a list
By osval in forum New To JavaReplies: 1Last Post: 07-30-2007, 05:43 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks