Solved

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

Posted on 2010-09-20
4
310 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

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: …
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

831 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