Results 1 to 2 of 2
Thread: skipping input
- 02-11-2008, 04:34 AM #1
Member
- Join Date
- Feb 2008
- Posts
- 1
- Rep Power
- 0
skipping input
Hi, every1. I am new to java and i need to read in a text file.
This is my text file.
Name = Jack
Address = 123 Ripley, Singapore 7666322
I need to read in the "Jack" and the address without reading in the "Name =" and the "Address =" using Scanner.
This is my method:
try
{
Scanner input = new Scanner(new File(fileName));
while(input.hasNext())
{
input.next(); input.next();
String name = input.nextLine().toUpperCase();
input.next(); input.next();
String address = input.nextLine();
new Customer(name, address);
numOfCustomers++;
}
System.out.println(numOfCustomers+" records read.");
}
can anybody suggest a better way of doing it if there is more than 2 variables?
Thank you.
- 02-12-2008, 07:09 PM #2
Welcome to the Java Forums windie
Your logic should simply be to the tune of:
i) read in the line
a) read up to equals sign, disregard
b) read past equals sign, true
You can incorporate that logic into your code with a multitude of API methods available to you.
See you around!Vote for the new slogan to our beloved Java Forums! (closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice? Vote now!
Got a little Capt'n in you? (drink responsibly)
Similar Threads
-
How to get input from Console
By karma in forum New To JavaReplies: 8Last Post: 08-13-2010, 09:32 PM -
cant take input from user
By new_1 in forum New To JavaReplies: 6Last Post: 12-25-2007, 07:38 AM -
input placed in array
By smilejava in forum New To JavaReplies: 5Last Post: 11-12-2007, 07:29 AM -
input placed in array
By smilejava in forum New To JavaReplies: 1Last Post: 11-05-2007, 12:32 PM -
how to take input and verify input in Java programs
By bilal_ali_java in forum Advanced JavaReplies: 0Last Post: 07-21-2007, 08:46 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks