How to control the read index position of a BufferedReader object ?
Hello:
I need to read a text file in order to insert semicolons when TXT, TAB consecutive are found, to convert the file to a Comma Separated Values .csv. I am using a BufferedReader and it's read() method to read one char per time, but I need to know what type (TXT or TAB) is last character and don't know how to control the index position in a loop like charAt(i) does it:
BufferedReader in =new BufferedReader(new FileReader(filename));
char ch = (char)in.read();
See:
.../Java/jdk1.6.0/docs/api/java/io/BufferedReader.html#read()
Thanks petes1234
1) I want to build a java macro to convert txt to csv (comma separated values) files.
Heres a sample of text files.
805Tempo•Elegant, contemporary design
•16-1/8” round
•Above counter installation
•Basin: 7-1/2” deep
•Colors: White and Standard Colors: Biscuit and Classic Bone
•Outstanding Protection - The Mansfield?limited lifetime warratny
•Meets or exceeds ANDI/ASME A112.19.2
•Meets or exceeds Canadian Standards Association CSA B45
825Monet•Graceful, curved design adds instant elegance to any bathroom d閏or
•17-1/4” a 14” oval
•Above counter installation
•Bain: 4-1/4” deep
•Colors: White, Standard Colors: Biscuit, Classic Bone and Designer Colors: Black
•Outstanding Protection - The Mansfield?limited lifetime warranty
•Meets or exceeds ANDI/ASME A112.19.2
•Meets or exceeds Canadian Standards Association CSA B45
2) I need to separate by semicolons:
code;"Model";"Features"\n
code;"Model";"Features"\n
code;"Model";"Features"\n
So I detect them by sequentially taking a character sample and remember last.
If TXT, TXT is found, just add it.
If TXT, TAB is found, insert a semicolon before TAB.
If TAB, TXT is found, just add it.
If TAB, TAB is found, do nothing, not add. (avoids extra TABS on csv)
Result should look like this:
805;"Tempo";"•Elegant, contemporary design•16-1/8” round•Above counter installation•Basin: 7-1/2” deep•Colors: White and Standard Colors: Biscuit and Classic Bone•Outstanding Protection - The Mansfield?limited lifetime warratny •Meets or exceeds ANDI/ASME A112.19.2•Meets or exceeds Canadian Standards Association CSA B45
825;"Monet";"•Graceful, curved design adds instant elegance to any bathroom d閏or"
...
3) I read one char per time using:
BufferedReader in = new BufferedReader(new FileReader(filename));
ch = (char)in.read()
Thanks forward.