Results 1 to 6 of 6

Thread: Method to return number of line

  1. #1
    Join Date
    Dec 2009
    Posts
    192

    Method to return number of line

    Hello,
    I have 2 questions about the files. Firstly, are there any method to know the number of lines in a file? For the moment I am reading a file line by line until the end to get the number of lines but not really great, especially if the file is heavy reading. Then I have a program that must read a file and retrieve all rows in a table. I again made a line by line reading of the file with a readLine () and it works well. My problem is that most of the time, the file will read a file and large enough so I sometimes have problems with memory even increasing RAM can use Eclipse. So I wanted to know if there was a method to retrieve all rows of a file without having to call to readLine (). Thank you in advance for your help.
    Last edited by Vodka; 13-01-2010 at 02:43 PM.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Method to return number of line

    Hi,
    There are things in nio library, but in your case I do not think they will work. There are at least nothing that would know the number of lines of a file without reading this file. Note nonetheless that to count the number of lines you are not at all obliged to store the rows in a table or elsewhere. If you increase the RAM that Eclipse can use, it is not surprising that it works through. I suggest instead of increase the RAM for your own programs.

  3. #3
    Join Date
    May 2008
    Posts
    2,389

    Re: Method to return number of line

    Hello,
    If the program runs in Linux / Unix, it may be appropriate if the file is very large, to request directly in the result (with the command "wc"). This can be done through Runtime.exec (): attention, it will retrieve and process the output stream of this method. Just try the exec() method and try if it works and post the result what you get.

  4. #4
    Join Date
    Dec 2009
    Posts
    192

    Re: Method to return number of line

    Hello,
    My program runs on windows. In fact, here is a more accurate and simpler for what I do. My application is divided into 2 parts. Initially, a window with 2 buttons, each being treated. One of them consists of:
    1. I open a dialog box allowing the user to select the file to read (use class JFileChooser)
    2. I read once the file for the total number of lines
    3. I read a second time my file and retrieve each line of the file into an ArrayList
    4. I sort each row present in the ArrayList of its kind (each line has a different marker following data type) and saves it to an ArrayList (ArrayList existing type of data)
    5. I display a dialog box with check buttons (+ OK and Cancel button) allows the user to say what type of data it wishes.

    Step 2 because by Step 3, I display the same time a ProgressBar so that the user sees the progress of treatment.
    My problem is that the treatment is perfectly except that when viewing the ProgressBar in Step 3, I have the window but it is white inside and ditto for Step 4.
    This is not a coding problem because if I take the first screen select the part of the application to do and then I go directly to Step 1, everything works normally. So that's why I think it's a memory problem (at least I see no other reasons!).
    So, since I code with Eclipse, I put in VM Arguments-Xmx512m but nothing changes, which means may say I'm wrong and it does not come from memory.

  5. #5
    Join Date
    May 2008
    Posts
    2,389

    Re: Method to return number of line

    Hello,
    For Step 2, may be you'd better report to you based on the number of bytes of the file, information accessible through the File class, which is not required to browse the entire file. For JProgressBar that does not advance, you can try some thing else there. I recommend you not to use the it, instead of it just think of an alternative.

  6. #6
    Join Date
    Dec 2009
    Posts
    192

    Re: Method to return number of line

    Hello,
    I posted a new dialog with a button after I ProgressBar and I also have the same problem as the window appears but not the button. So I do not think the class SwingWorker me useful. In attachment I made 2 prints screens to better understand what I have. If I start directly by the class that we process, while the display is good. If I first open a dialog box to select my treatments and when I call the same class for my first test, the display problem.

Similar Threads

  1. Urgent Help with return method toString() Java!!
    By vizu in forum Software Development
    Replies: 3
    Last Post: 01-05-2011, 11:48 PM
  2. what are the possible return types of a main method?
    By \"Dritan\" in forum Software Development
    Replies: 3
    Last Post: 08-01-2011, 03:50 AM
  3. Method with multiple return types
    By ISAIAH in forum Software Development
    Replies: 5
    Last Post: 25-02-2010, 05:10 AM
  4. How to return value for void method?
    By Klaty in forum Software Development
    Replies: 5
    Last Post: 21-01-2010, 11:42 AM
  5. Return a strongly typed array from the ToArray method
    By Eleazar in forum Software Development
    Replies: 2
    Last Post: 06-05-2009, 01:32 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,750,434,104.51303 seconds with 16 queries