![]() |
| ||
| Need Help to read .txt file and store its contents The code on which I am working, suppose to read the contents of a file "applicants.txt" linewise and store it in a string array. Each element of array should hold one line and so on. I also want to automate the code so that when end of file is reached it should stop reading file. Find below my code and the structure of "applicants.txt" file. Current code displays only last two lines from str array and a series of 'null' strings thereafter. I am using BlueJ environment to develop and run this code. Kindly guide me in correct direction. Structure of "applicants.txt" file Cynthia Powell 99031911 F 17 18000 Y Peter Best 99051234 M 32 70000 N Andrew White 99042367 M 25 20000 Y Jane Asher 99075235 F 29 5000 Y Malcom Evans 98763476 M 18 15000 Y |
| ||
| Re: Need Help to read .txt file and store its contents So... you've got a few problems with your code... one really really bad thing is that you make each method throw an exception. that means you will never see if there are any errors. You were getting a bunch of nulls because you were storing values in an array of 50 and printing out each spot... here is the fixed code. I left it as close to normal as possible import java.util.*; |
| ||
| Re: Need Help to read .txt file and store its contents Hi Libran, To help debug your code, try adding some println statements to gain a better understanding of what is going on. Please see my comments below. Hopefully these println statements will help you debug your program. Don't forget to comment them all out for your final program! ;) |
| All times are GMT -4. The time now is 8:08 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC