Solved

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

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…

706 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now