Results 1 to 5 of 5
- 12-08-2011, 10:46 PM #1
Member
- Join Date
- Dec 2011
- Posts
- 5
- Rep Power
- 0
Help needed with reading a text file
I have to read a text file of names and then give each name a percentage. Then I have to output the names to 2 separate text files, one containing the names who scored higher than 40% and the other containing the names who scored under 40%.
This is what I have done so far and i have no idea where to go now! Any and all help would be greatly appreciated.
Java Code:import java.io.*; import java.util.*; public class TestResults { public static void main(String[] args) { String errs = ""; try { Scanner kybd = new Scanner (System.in); Scanner inFile = new Scanner(new File("Names.txt")); System.out.print("\nNames in file: \n"); while (inFile.hasNext()) { try { String value = inFile.nextLine(); System.out.println("Please enter a percentage for " + value + ": "); } catch (InputMismatchException ime) { String valueStr = inFile.next(); errs += "\n\t" + valueStr; } } inFile.close(); } catch (IOException ioe) { System.out.println("ERROR: " + ioe.getMessage()); } } }
- 12-08-2011, 11:09 PM #2
Senior Member
- Join Date
- Feb 2010
- Location
- Waterford, Ireland
- Posts
- 748
- Rep Power
- 10
Re: Help needed with reading a text file
Well you need to first take in the percentage, using that Scanner variable kybd.... Use if statements to determine if the percentage entered is less than or above 40
You will then need a way to write the names to text Files:
FileWriter (Java Platform SE 6)
BufferedWriter (Java Platform SE 6)
This should get you started, take the time to read the docs
- 12-09-2011, 12:17 PM #3
Member
- Join Date
- Dec 2011
- Posts
- 5
- Rep Power
- 0
Re: Help needed with reading a text file
Thanks for the help! How would i go about implementing this?
- 12-09-2011, 12:22 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 26
Re: Help needed with reading a text file
By reading the docs and trying to write some code based on that?
- 12-09-2011, 12:45 PM #5
Member
- Join Date
- Nov 2011
- Posts
- 4
- Rep Power
- 0
Similar Threads
-
Reading from a text file, then writing back to Text Area in Reverse
By medic642 in forum New To JavaReplies: 8Last Post: 07-17-2011, 03:38 PM -
File Reading..Help Needed
By spartan in forum New To JavaReplies: 1Last Post: 04-26-2011, 03:06 PM -
Help reading a text file.
By Kristoba in forum New To JavaReplies: 5Last Post: 03-11-2010, 09:42 AM -
Reading two text file and sum them up
By matt_well in forum New To JavaReplies: 36Last Post: 07-22-2008, 03:55 AM -
Reading text file
By Lennon-Guru in forum New To JavaReplies: 1Last Post: 12-16-2007, 12:38 AM
Bookmarks