Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
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…
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…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

863 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

23 Experts available now in Live!

Get 1:1 Help Now