Results 1 to 7 of 7
- 07-27-2011, 08:00 AM #1
Member
- Join Date
- May 2011
- Posts
- 97
- Rep Power
- 0
How to read text after delimiter in textfile ?
HI
I HAVE TEXT FILE, there will be only two columns
e.g: test, PS_JOB
all i have to do is read text after delimiter i have done following
this returns every value. i want only after delimiter.Java Code:Scanner scan = new Scanner(new File("textfile.txt")); scan.useDelimiter(","); while(scan.hasNext()){ System.out.println(scan.next()); }
Regards
Sandeep
- 07-27-2011, 08:06 AM #2
Why not read entire line and use String.split?
- 07-27-2011, 08:12 AM #3
I just realised your misconception. Using the delimeter does not automagically ignore text before and give you the text afterwards. What it does, it uses the delimeter as the break point instead of a line break.
If the text was "one,two,three". Using a comma as a delimeter you would get three values "one" "two" and "three". Without the delimeter you would get one value "one,two,three".
- 07-27-2011, 08:53 AM #4
Member
- Join Date
- May 2011
- Posts
- 97
- Rep Power
- 0
Hi junky,
how to print that split one, two , three is my doubt ?
Regrds
Sandeep
- 07-27-2011, 09:08 AM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,392
- Blog Entries
- 7
- Rep Power
- 17
Split on the comma, i.e. line.split(","); the split method returns an array of Strings where array[0] == "one", array[1] == "two" etc.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 07-27-2011, 09:12 AM #6
Member
- Join Date
- Jul 2011
- Posts
- 11
- Rep Power
- 0
how big is the file? If not too big, I would read each line into a string, and then invoke the substring method using the index of the "," + 1 as the start index. You can use indexOf to get the index of the comma and then add 1.
- 07-27-2011, 10:11 AM #7
Member
- Join Date
- May 2011
- Posts
- 97
- Rep Power
- 0
Similar Threads
-
read text from .pdf
By seghri in forum Java AppletsReplies: 0Last Post: 05-08-2011, 03:05 PM -
how to read only parts of textfile by java
By smn in forum SWT / JFaceReplies: 2Last Post: 10-08-2010, 03:31 AM -
Read text file
By Sean04 in forum New To JavaReplies: 18Last Post: 06-16-2010, 01:43 AM -
How to read DatePicker Text box value in jsf?
By kishan in forum JavaServer Faces (JSF)Replies: 1Last Post: 05-12-2010, 04:23 PM -
Read from a text file?
By aaronfsimons in forum New To JavaReplies: 3Last Post: 05-01-2009, 04:42 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks