Results 1 to 6 of 6
Thread: Help reading a text file.
- 03-10-2010, 08:34 PM #1
Member
- Join Date
- Mar 2010
- Posts
- 3
- Rep Power
- 0
Help reading a text file.
Hi, I'm new here and I'm having some trouble with a java program.
I have to read a text file (The user provides the name). The program must follow these rules as well.
The first rule is that a word consists of what the next() method of the Scanner class will return. The next() method returns a String that consists of all the characters in the input up to, but not including, the next “whitespace character”, where blank spaces, tabs, and newline characters are the whitespace characters.
The second rule: If the word has a single- or double-quotation mark as the first character of the word, remove it.
The third rule: Look at the last character of the word. If this last character is any one of •single-quotation mark, double-quotation mark, semi-colon, colon, period, comma, hyphen, exclamation point, question mark, remove it.
So far i have this
public class Trimming
{
public static void man(String [] args) throws IOException
{
File inputFile = new File( "Sample.txt" );
Scanner fileScan = new Scanner( inputFile );
int number = fileScan.nextInt();
Any suggestions/help?
- 03-10-2010, 09:20 PM #2
What?! :confused:
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 03-10-2010, 09:24 PM #3
Member
- Join Date
- Mar 2010
- Posts
- 3
- Rep Power
- 0
That is exactly what i am thinking haha. So what i basically have to do is print each word to a line, excluding special punctuation.
- 03-10-2010, 09:45 PM #4
So, start with just one line and get that sorted first:
Output:Java Code:String line = "this \'is\' a \"line\" !of! the $file$""; // do some magic here
this
is
a
line
of
the
file
The first thing that comes to mind is String.split().Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 03-10-2010, 09:55 PM #5
Member
- Join Date
- Mar 2010
- Posts
- 3
- Rep Power
- 0
Okay, so how exactly would i be able to get the words in in the text file to appear in the program. This is the only problem i am having. :) I'm using Scanner of course.
Say Name.txt is:
hello my name is John.
Output would appear exactly as what you showed.
- 03-11-2010, 08:42 AM #6
Uhm, using the nextLine() method from Scanner? I thought that would be obvious from the API.
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
Similar Threads
-
Reading in a text file
By TheRealHoff in forum AWT / SwingReplies: 10Last Post: 02-07-2010, 11:47 PM -
reading text file
By trofyscarz in forum New To JavaReplies: 1Last Post: 02-05-2010, 02:24 AM -
Reading a text file
By diegosened in forum New To JavaReplies: 4Last Post: 01-15-2010, 11:32 PM -
Reading two text file and sum them up
By matt_well in forum New To JavaReplies: 36Last Post: 07-22-2008, 02:55 AM -
Reading text file
By Lennon-Guru in forum New To JavaReplies: 1Last Post: 12-15-2007, 11:38 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks