Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Java: what class to use to open large .log files? (20MB)

Posted on 2010-09-20
4
311 Views
Last Modified: 2013-11-23
Hello Experts,

I am trying to write a program that opens large .log files (20MB each).

I am using the class below, but when trying to open a file the application hangs...

do I need to use a different class?

Thx so much for your help....

Regards,

chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

filter = new FileNameExtensionFilter(".txt and .log files", "txt", "log");
chooser.setFileFilter(filter);

try {
	int code = chooser.showOpenDialog(chooser);
	if (code == JFileChooser.APPROVE_OPTION) {
		if(contents == null) {
                    contents = new StringBuilder();
                }

	    input =  new BufferedReader(new FileReader(chooser.getSelectedFile().getAbsolutePath()));

		try {
			String line = null;

			 while (( line = input.readLine()) != null){
			          contents.append(line);			                contents.append(System.getProperty("line.separator"));
			        }
			      }
			      finally {
			        input.close();
			      }
			    }

		} catch (IOException ex){
			      ex.printStackTrace();
			}

		pane.setText(contents.toString());

Open in new window

0
Comment
Question by:epifanio67
  • 2
  • 2
4 Comments
 
LVL 26

Expert Comment

by:ksivananth
ID: 33722914
you are trying to read the entire 20MB into SB and then trying to set it to the UI, the UI may give slugish response... why don't you try the existing UI http://vigilog.sourceforge.net/features.html to open your file
0
 

Author Comment

by:epifanio67
ID: 33727553
thx ksivananth,

Well, I am in learning the API while coding few ideas... that's why I am not using existing apps...

any other thoughts?

thx,


0
 
LVL 26

Accepted Solution

by:
ksivananth earned 500 total points
ID: 33732021
>>Well, I am in learning the API while coding few ideas

then, don't push the entire 20MB to UI at a time, i.e., limit the content ahown at a time and show the remaining when required. For e.g., you may show 100lines/rows at a time in the UI, based on the user scrolling, you may remove exisitng from UI and load new to UI...
0
 

Author Closing Comment

by:epifanio67
ID: 33739037
thank you!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Visual Studio 2013 5 79
Breakpoint problem 8 100
How to jump to matching brace in eclipse editor ? 1 317
Configure a Local PHP Interpreter for Phpstorm 2 325
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question