Computer HardwareXbox GamesGameCubePlaystation 2PSOnePC/Windows GamesGameboy AdvanceDreamcastNintendo 64Gameboy ColorNintendo DSSony PSPXbox 360Nintendo Wii GamesPS3 Games

Neoseeker Forums » Programming and Design » General Programming » [Java] Looping Through A File

REPLY TO THIS THREAD   START NEW THREAD
| Sharemore
Options: Print   subscribe   remove   PM this thread to a friendNeoPM  
subscribe to thread Topic: [Java] Looping Through A File
Chiggins
(devpen) (crs) (badass)
(moderator)

HTML/CSS & NeoHome Help



Chiggins' profileChiggins' neohomeEmail ChigginsNeoPM ChigginsChiggins' gallery (412 images)
total posts: 2499
neopoints: 204
GameGrep pts: 613
since: Jun 2003
Nov 09, 09 at 10:17pm
[Java] Looping Through A File

Alright, I'm using the Scanner class to run through some information inside a text file. The text file is as follows (the "arrows" show the end of each entry):

quote
Dominic M. Ippolito UNKNOWN 2175551212
UNKNOWN <---- END
Shirley A. White 05/30/1959 3094388016
ADDRESS
101 N Main St
Normal
IL
61761 <---- END
Mickey T. Mouse UNKNOWN UNKNOWN
UNKNOWN <---- END
Felicity M. Congdon 09/25/1982 UNKNOWN
UNKNOWN <---- END
As you see, they entries can be of various length. How could I create a loop to go through each one of those entries?


-------------------
quote   quick quote   edit   quick edit   del  searchposts in thread  report
Liam
Relentless



Liam's profileLiam's neohomeNeoPM Liam
total posts: 9143
since: Dec 2001
Nov 11, 09 at 8:23pm
re: [Java] Looping Through A File

If they can be of various length and spanned over various lines then it's near on impossible to automate identifying individual entries. The input will require something to specify where a new entry begins, whether its a unique character or pattern.
quote   quick quote   edit   quick edit   del  searchposts in thread  report
Chiggins
(devpen) (crs) (badass)
(moderator)

HTML/CSS & NeoHome Help



Chiggins' profileChiggins' neohomeEmail ChigginsNeoPM ChigginsChiggins' gallery (412 images)
total posts: 2499
neopoints: 204
GameGrep pts: 613
since: Jun 2003
Nov 11, 09 at 10:33pm
re: [Java] Looping Through A File

I was able to figure this out. inputFile is the Scanner of the file being read, and person is the Person class to where the information is being read from.

Since the first two lines of each entry in the text file will always be there, we look at those. If the second one reads UNKNOWN, we stop, because we don't know the persons address. If we do know it, we continue to read until the end of the address.

code
while (inputFile.hasNext())
{
	person.readRecord(inputFile);
	System.out.println(person.toString());
}


-------------------
quote   quick quote   edit   quick edit   del  searchposts in thread  report
[All dates in (PT) time]Threads List   « Next Newest   Next Oldest »
REPLY TO THIS THREAD   START NEW THREAD


search:
search posts by username:
Neoseeker Forums » Programming and Design » General Programming » [Java] Looping Through A File



Jump to another forum:

Powered by neoforums v0.9.8b (equilibrium)
Copyright Neo Era Media, Inc. 1999-2009

neoseeker forum community
Neoseeker.com   |   Forum Rules   |   Forum FAQ   |   Neoseeker Terms of Use   |   Supermods On Duty [ server id: nova ··· elapsed: 0.1523480415]
Affiliated sites:   GameGrep - Football Manager Wiki - Halo Wiki - MGS Wiki - GTA Wiki - Smackdown Wiki - Zelda Wiki - PS2seeker - Xbox seeker - DEVPEN - GFXcess