Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-11-2008, 05:34 AM
Member
 
Join Date: Feb 2008
Posts: 1
windie_86 is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 02-12-2008, 08:09 PM
CaptainMorgan's Avatar
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 841
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
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!
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums!
(closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
!
Got a little Capt'n in you? (drink responsibly)
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
cant take input from user new_1 New To Java 6 12-25-2007 08:38 AM
input placed in array smilejava New To Java 5 11-12-2007 08:29 AM
input placed in array smilejava New To Java 1 11-05-2007 01:32 PM
how to take input and verify input in Java programs bilal_ali_java Advanced Java 0 07-21-2007 09:46 AM
How to get input from Console karma New To Java 2 05-20-2007 12:32 PM


All times are GMT +3. The time now is 07:52 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org