Results 1 to 6 of 6
- 02-18-2010, 12:45 PM #1
Member
- Join Date
- Feb 2010
- Posts
- 29
- Rep Power
- 0
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 :
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.Java Code: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(); } }
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 :
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!!Java Code:1336咸 BAB0 喊 han3 BCEA 缄 jian1 BCEE 碱 jian3 BCF5 减 jian3 CFCC 咸 xian2 F3F0 箴 zhen1 1337感 B8D0 感 gan3 BAB3
Anyone has an idea ?
Thanks in advance for your help guys!Last edited by ze snow; 02-18-2010 at 12:58 PM.
- 02-18-2010, 12:53 PM #2
What I see from the start is that you skip the first line of the input file:
Java Code:String inLine = null; //inLine = br.readLine(); <.--- What for??? while ((inLine = br.readLine()) != null) {Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 02-18-2010, 12:58 PM #3
Member
- Join Date
- Feb 2010
- Posts
- 29
- Rep Power
- 0
Ah sorry, that's a mistake.
This was part of a small test I did before and I forgot to remove it when I posted this topic.
I edit it.
Thanks for noticing btw.
Still the same problem without this line....
- 02-18-2010, 01:01 PM #4
Ok, Ive tested with this:
output:Java Code:FileReader fr = new FileReader("D:/pinyinlist.txt"); FileWriter fw = new FileWriter("D:/pinyoutlist.txt"); BufferedReader br = new BufferedReader(fr); PrintWriter pw = new PrintWriter(fw); String inLine = null; //inLine = br.readLine(); int linesRead = 0; int linesWritten = 0; int linesSkipped = 0; while ((inLine = br.readLine()) != null) { linesRead++; if (inLine.trim().length() != 0) { pw.println(inLine); linesWritten++; }else{ linesSkipped++; } } pw.flush(); pw.close(); br.close(); System.out.println("Read : " + linesRead); System.out.println("Skip : " + linesSkipped); System.out.println("Write: " + linesWritten);
Read : 1501
Skip : 845
Write: 656
Outputfile attached.Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 02-18-2010, 01:07 PM #5
Member
- Join Date
- Feb 2010
- Posts
- 29
- Rep Power
- 0
Wow, it works now...
But I don't understand why, can you explain to me please ?
is it because of the flush() method ?
Thanks so much!
- 02-18-2010, 01:19 PM #6
To be honest, I always flush the output streams and close the resources. I never use Streams, your best chance is to have a look at the API and the IO tutorial:
Lesson: Basic I/O (The Java™ Tutorials > Essential Classes)Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
Similar Threads
-
empty arrays.
By circuspeanuts in forum New To JavaReplies: 11Last Post: 04-06-2009, 07:08 PM -
KeyBindings Empty Key?
By Unome in forum Java AppletsReplies: 1Last Post: 10-24-2008, 07:28 PM -
Empty ResultSet
By Java Tip in forum Java TipReplies: 0Last Post: 02-09-2008, 08:36 PM -
Removing empty lines from code using Eclipse
By javaplus in forum EclipseReplies: 1Last Post: 12-14-2007, 09:21 PM -
BufferedReader empty
By Peter in forum Advanced JavaReplies: 2Last Post: 07-02-2007, 06:52 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks