Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Supressing empty lines and does not do until the end! Why ?

  1. #1
    Junior Member
    Join Date
    Feb 2010
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Supressing empty lines and does not do until the end! Why ?

    Hi guys,

    I really don't understand what's happening in my program, almost mad!

    Basically, it just takes a file in input and outputs a file.
    What it tries to do is just suppress all the empty lines, very simple.

    Here is the body of my method :

    private static void suppressSpaces(String in, String out) {
     
    		try {
    			FileReader fr = new FileReader(in);
    			FileWriter fw = new FileWriter(out);
     
    			BufferedReader br = new BufferedReader(fr);
    			PrintWriter pw = new PrintWriter(fw);
     
    			String inLine = null;
     
    			while ((inLine = br.readLine()) != null) {
     
    				if (inLine.trim().length() != 0) {
    					pw.println(inLine);
    				}
    			}
     
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    	}

    The input file has 20'609 lines to process and I don't understand why but it kind of stops processing after the line 20'350 about. So in the output file, there is about 97-98% of what there should be normally. No idea why...The file is very regular, I mean there is nothing special at the line 20'350, it's just the same as before.

    I attached a sample input file in TXT format (the whole file exceeds the limit), please have a look if you want.

    Here are the 10 last lines of the output file :

    1336咸
    BAB0 喊  han3
    BCEA 缄  jian1
    BCEE 碱  jian3
    BCF5 减  jian3
    CFCC 咸  xian2
    F3F0 箴  zhen1
    1337感
    B8D0 感  gan3
    BAB3

    You can see it stops in the middle of the category 1337 and there is total of 1353 categories so it's almost done but dunno why, it doesn't go until the end!!

    Anyone has an idea ?

    Thanks in advance for your help guys!
    Attached Files Attached Files


  2. #2
    Junior Member
    Join Date
    Feb 2010
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Supressing empty lines and does not do until the end! Why ?

    Just found the answer -.-

    Needs to perform the flush() method on the PrintWriter at the end and yeah...it flushes what was not output before ^^

    Jeez!

Similar Threads

  1. Reading from a file, multiple lines
    By MysticDeath in forum File I/O & Other I/O Streams
    Replies: 5
    Last Post: October 15th, 2009, 02:40 AM
  2. Java error while using BufferedReader class to read a .txt document
    By Jchang504 in forum File I/O & Other I/O Streams
    Replies: 6
    Last Post: February 4th, 2009, 07:55 PM
  3. How to assign values from a file to an arraylist of objects?
    By nadman123 in forum Collections and Generics
    Replies: 3
    Last Post: September 15th, 2008, 01:07 PM