Regarding your comment to adeel's answer:
Thanks adeel825, however I dont know where to put the "\t".. so far I use this method: new PrintStream(fout).println (name); new PrintStream(fout).println (exercise); new PrintStream(fout).println("10 minutes");
First, don't call "new PrintStream(fout)
" everytime you print something. Do this:
PrintStream ps = new PrintStream(fout);
ps.print(name);
ps.print('\t');
ps.print(exercise);
ps.print('\t');
ps.print(time);
ps.println();
Or simply:
PrintStream ps = new PrintStream(fout);
ps.println(name + '\t' + exercise + '\t' + time);
Edit
In response to your comment:
one more question...some of the name are too long and it requires more tab..I have put ps.print('\t','\t'); but it seems not working..
If this is a problem, it sounds like you are trying to store them in the manner you want to display them. I had assumed you were trying to store them in a way that would be easy to parse programmatically. If you want to store them displayed in columns, I'd suggest padding with spaces rather than tabs.
If you know that all the columns are going to be less than, say, 30 characters wide, you could do something like this with printf:
ps.printf("%30s%30s%30s%n", name, exercise, time);
That syntax can look quite byzantine if you're not used to it.. basiclly each "%30s" means pad the string argument so that it is at least 30 characters wide. Your result won't look right if any of the values are 30 or more characters wide. If you can't know ahead of time, you'll have to loop through the values in each column to determine how wide the columns need to be.