|
-
File Handling Problems
OK, I am having problems reading text from a file. The text in the folder takes the following form.
0.01 0.01 191650 5 | ae United Arab Emirates
0.01 0.01 146570 8 | am Armenia
I only wish to read data from the third, fourth, sixth and seventh column. Curerntly I have been using this code to read all the data.
data = inFile.readLine();
while(data != null)
{
StringTokenizer st = new StringTokenizer(data);
valA = st.nextToken();
valB = st.nextToken();
valC = st.nextToken();
valD = st.nextToken();
valE = st.nextToken();
valF = st.nextToken();
valG = st.nextToken();
valH = st.nextToken();
valI = st.nextToken();
System.out.println(valF+" "+valC+" "+valD+" "+valG+
" "+valH+" "+valI);
data = inFile.readLine();
}
This works fine for the first row of data, but obviously fails on the second and throws an exception as there are less tokens in this row. Can anyone suggest a way of handling this data?
Cheers,
Munki
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks