This week's giveaways are in the MongoDB and Jobs Discussion forums.
We're giving away four copies of Mongo DB Applied Patterns and 4 resume reviews from Five Year Itch and have the authors/reps on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes Reading txt file where tab is used? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Mongo DB Applied Patterns this week in the MongoDB forum
or a resume review from Five Year Itch in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Reading txt file where tab is used? " Watch "Reading txt file where tab is used? " New topic
Author

Reading txt file where tab is used?

kristian jarvi
Greenhorn

Joined: Jan 19, 2002
Posts: 9
I'm parsin a text file into equal length
peaces and it's workin ok.
but if i use tab (\t) my text file for
it won't work.
can i ignore those tab's or can i
change them into spaces.
(very difficult to explain)
----------------------
(here i use space to select place where to
write text,this way it works fine)
if my txt file looks like this:

outcome is

but if i use tab to select the place where to startwriting(if i use tab after test and then write folks) outcome isn't same.
it's something like this

-code-
import java.io.*;
class Parse{
public static void main(String []args)throws IOException {
BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
StringBuffer sb=new StringBuffer();
String tmp= "";
int spacefound=0;
try{
File inputFile = new File ("help.txt");
FileReader fis =new FileReader(inputFile);
BufferedReader bis = new BufferedReader(fis);
for(String line=bis.readLine().trim();line != null;line=bis.readLine()) {
sb.append(" ").append(line);
}
}
catch ( FileNotFoundException fnfe ) {
fnfe.printStackTrace();
}
catch ( IOException ioe ) {
ioe.printStackTrace();
}
String test=sb.toString();
test=test.trim();

int l=test.indexOf(" ");
for(int i=0;i<test.length();i++){
char c=test.charAt(i);
if(c!=' ') tmp+=""+c;
if(c==' ' && (spacefound<1) && !(tmp.equals(""))) {
tmp+=""+c;
spacefound++;
}
if(tmp.length()==l) {
System.out.println(tmp);
tmp="";
spacefound=0;
}
}
if(tmp.length()<l){
for(int i=0;i<=(l-tmp.length());i++)
tmp+=""+' ';
}
System.out.println(tmp);
}
}
[ February 08, 2002: Message edited by: Jim Yingst ]
Shivaji Marathe
Ranch Hand

Joined: Jan 11, 2002
Posts: 203
Have you tried using StringTokenizer ?
 
I agree. Here's the link: http://jrebel.com/download
 
subject: Reading txt file where tab is used?
 
Similar Threads
Problems using/making method!
Readin a text file and cuttin the text
how to check if file is empty
Reading every line from a file to string
I Need help with file handling