#1
  1. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2001
    Location
    Yogyakarta, Indonesia
    Posts
    22
    Rep Power
    0

    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. #2
  3. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    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 &nbsp;, or don't worry so much about formatting.

IMN logo majestic logo threadwatch logo seochat tools logo