|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
|||
|
|||
|
Reading Text File
I've used this code to read a text file. But the problem is all spaces and tabs, regardless how many spaces and tabs, became only one space. Can anybody give me a pointer where the problem is?
Code:
public void readingFile() {
try {
RandomAccessFile raf = new RandomAccessFile("c://Invitation.txt", "rw");
//raf.seek( 0 ); // Starts at the beginning of the file
String thisString = new String();
String txtTemp = "";
do {
thisString = raf.readLine();
txtTemp += thisString + "<BR>";
} while ( raf.getFilePointer() < raf.length() );
setOutputText(txtTemp);
raf.close();
}
catch (IOException e) {
System.out.println("Error opening file: " + e);
}
}
Thanks |
|
#2
|
|||
|
|||
|
I assume you're output this to html? The problem is that html condenses all white space to a single space. You can either wrap your output in <pre></pre> tags, go through and replace spaces with , or don't worry so much about formatting.
![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Java Help > Reading Text File |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|