Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2010-09-20
4
Medium Priority
?
318 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
[X]
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
  • 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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. …
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 column That will then direct you to their download page. From that p…
The viewer will learn how to synchronize PHP projects with a remote server 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.

610 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