A usefull way to read a long file

Hi,
What's the best and usefullest way to read a large file?
I do use a LineNumberReader but i think it reads a little slow...
To open the same file in an text editor reacts in less a millisecond while my LineNumberReader nees more time to read the entire file...
Any suggestions?
Olek

re,
how can i determine how a file contains "real" text or only sensles characters?
The file i readed seems to be a binary file in your meaning.
here is the method i use
// Threader.FileReadThreader is a instance of SwingWorker
public static String readPlainTextFile(File f, Threader.FileReadThreader fileReader) throws IOException {
        final StringBuilder strBuild = new StringBuilder();
        final DataInputStream dis = new DataInputStream(new BufferedInputStream(new FileInputStream(f)));
        final int readByte = BUFFER;
        final int fileLength = (int) f.length();
        float step = fileLength / readByte;
        byte[] buffer = new byte[fileLength];
        int off = 0;
        if (fileReader != null) {
            float percent = 0F;
            while (off < fileLength - readByte) {
                dis.readFully(buffer, off, readByte);
                String tempSequence = new String(Arrays.copyOfRange(buffer, off, off + readByte - 1));
                strBuild.append(tempSequence);
                off += readByte;
                percent += step;
                fileReader.doPublish(new Object[]{Math.round(percent), tempSequence});
            // read the remaining bytes
            int last = fileLength - off;
            dis.readFully(buffer, off, last - 1);
            String tempSequence = new String(Arrays.copyOfRange(buffer, off, off + last - 1));
            strBuild.append(tempSequence);
            percent += step;
            fileReader.doPublish(new Object[]{Math.round(percent), tempSequence});
            return strBuild.toString();
        } else {
            dis.readFully(buffer);
            return new String(buffer);
    }As you can see i modified your code.
Hm i got the error why the JTextArea do only display
one large line of characters...
i forgot to set line wrap ...
but now the app freezes reading the large binary file ...
with a smaller file all works ok.
Any ideas?
regards.
Olek

Similar Messages

  • What is the best, most efficient way to read a .xls File and create a pipe-delimited .csv File?

    What is the best and most efficient way to read a .xls File and create a pipe-delimited .csv File?
    Thanks in advance for your review and am hopeful for a reply.
    ITBobbyP85

    You should have no trouble doing this in SSIS. Simply add a data flow with connection managers to an existing .xls file (excel connection manager) and a new .csv file (flat file). Add a source to the xls and destination to the csv, and set the destination
    csv parameter "delay validation" to true. Use an expression to define the name of the new .csv file.
    In the flat file connection manager, set the column delimiter to the pipe character.

  • What's the best way for reading this binary file?

    I've written a program that acquires data from a DAQmx card and writes it on a binary file (attached file and picture). The data that I'm acquiring comes from 8 channels, at 2.5MS/s for, at least, 5 seconds. What's the best way of reading this binary file, knowing that:
    -I'll need it also on graphics (only after acquiring)
    -I also need to see these values and use them later in Matlab.
    I've tried the "Array to Spreadsheet String", but LabView goes out of memory (even if I don't use all of the 8 channels, but only 1).
    LabView 8.6
    Solved!
    Go to Solution.
    Attachments:
    AcquireWrite02.vi ‏15 KB
    myvi.jpg ‏55 KB

    But my real problem, at least now, is how can I divide the information to get not only one graphic but eight?
    I can read the file, but I get this (with only two channels):
    So what I tried was, using a for loop, saving 250 elements in different arrays and then writing it to the .txt file. But it doesn't come right... I used 250 because that's what I got from the graphic: at each 250 points it plots the other channel.
    Am I missing something here? How should I treat the information coming from the binary file, if not the way I'm doing?
    (attached are the .vi files I'm using to save in the .txt format)
    (EDITED. I just saw that I was dividing my graph's data in 4 just before plotting it... so It isn't 250 but 1000 elements for each channel... Still, the problem has not been solved)
    Message Edited by Danigno on 11-17-2008 08:47 AM
    Attachments:
    mygraph.jpg ‏280 KB
    Read Binary File and Save as txt - 2 channels - with SetFilePosition.vi ‏14 KB
    Read Binary File and Save as txt - with SetFilePosition_b_save2files_with_array.vi ‏14 KB

  • I have written a binary file with a specific header format in LABVIEW 8.6 and tried to Read the same Data File, Using LABVIEW 7.1.Here i Found some difficulty.Is there any way to Read the Data File(of LABVIEW 8.6), Using LABVIEW 7.1?

    I have written a binary file with a specific header format in LABVIEW 8.6 and tried  to Read the same Data File, Using LABVIEW 7.1.Here i Found some difficulty.Is there any way to Read the Data File(of LABVIEW 8.6), Using LABVIEW 7.1?

    I can think of two possible stumbling blocks:
    What are your 8.6 options for "byte order" and "prepend array or string size"?
    Overall, many file IO functions have changed with LabVIEW 8.0, so there might not be an exact 1:1 code conversion. You might need to make some modifications. For example, in 7.1, you should use "write file", the "binary file VIs" are special purpose (I16 or SGL). What is your data type?
    LabVIEW Champion . Do more with less code and in less time .

  • Best way to read from a file

    What would be the best way to read from a file. Which classes do I need to use?
    I have to write a program, which reads data from a comma separated flat file, parse it and after inserting some busineess logic insert into a databse .
    I will have to read the data line by line.
    Any help????

    I would use:
         public void readData()
              try
                   data = new String[this.countRows("comp.txt")][];
                   BufferedReader br = new BufferedReader(new FileReader("comp.txt"));
                   for(int x = 0; x < data.length; x++)
                        StringTokenizer temp = new StringTokenizer(br.readLine(), "?");
                        data[x] = new String[temp.countTokens()];
                        for(int y = 0; y < data[x].length; y++)
                             data[x][y] = temp.nextToken();
              catch(Exception e)
                   System.out.println(e.toString());
         private int countRows(String f)
              int t = 0;
              try
                   BufferedReader brCountRows = new BufferedReader(new FileReader(f));
                   while(brCountRows.readLine() != null)
                        t++;
              catch(Exception e)
                   System.out.println(e.toString());
                   return t;
              return t;
         }It works deliciously!

  • What is the best way to read in a file?

    i'm currently doing it like this:
    Vector inVector = new Vector();
    try
    File file = new File( "C:/1jkiesel/testAgent/Customers.txt" );
    BufferedReader in = new BufferedReader( new FileReader( file ) );
    String str;
    while( ( str = in.readLine() ) != null )
    inVector.add( str );
    in.close();
    catch( IOException e )
    e.printStackTrace();
    is there a better way? especially th full file path thing...

    I did a search in the formums for
    "best practice read file"
    there were too many results so it was not very helpful
    I think that the best practice is to look at the "read" methods for
    each stream super class and decide which one is best for the particular
    application you have.
    I ask a follow up question:
    Is there a web page where we can find some comparisons of the various methods? Comparisons like speed, size, exception handling?
    hope this helps

  • Is there any way to read the pdf file in java

    Hai,
    i need some advice from anyone that is there anyway to read the pdf file directly from java...
    Without converting to other files(txt,html)
    if it is possible please help me..
    Thank you

    Or use the Adobe one (search the adobe site). Or search this forum, this is one of the Top Ten Qestions Asked here.

  • Any way to read/view .xps files on a Mac running 10.4.9 ?

    I've searched the FAQs and the forums, and I've googled in vain.
    I'm curious to view the .xps files on Microsoft ClearType page.
    I found something called NiXPS.app for MAC OS X, but it fails to view or read anything in the XPS files, though it does recognize and "open" them without showing them.
    Is anyone aware of a reader for .sps files on a Mac?
    Dual 1.25MHz MDD G4, 2GB RAM, 4 int dr.,2ext FW drives   Mac OS X (10.4.9)  

    You can get a .XPS file converter from the Beast of Redmond itself. <http://www.microsoft.com/mac/downloads.aspx> I've got no idea how well, or even if, it works; the downloads page says that it's v 0.1.1 beta. Try at your own risk.

  • Best way to read a CSV file into an internal table

    Hi,
    I have a comma seprated file, which I need to read into an internal table, and be able to look at particular values - basically looping round and populating BDC fields. Whats the easiest way of doing this?

    The easiest way would be to define a flat interal table.
    Data: begin of itab occurs 0,
          rec(1000) type c,
          end of itab.
    Then call the function module GUI_UPLOAD to get the data into your internal table from the file on the frontend. I assume that you know how to use this function module.  You could also use the method GUI_UPLOAD of the class CL_GUI_FRONTEND_SERVICES.
    For example,  say you have a comman delimited file with materail number, plant, quantity in it.
    4000001,0004,1.00
    4000002,0006,2.00
    Define another internal table to hold the data.
    Data: begin of itab2 occurs 0,
          matnr type mara-matnr
          werks type marc-werks
          quant(10) type c.
          end of itab2.
    Then loop at the internal table(ITAB) and use the split statement to split it up into the appropriate fields of the other interal table(ITAB2). 
    Loop at itab.
    clear itab2.
    split itab-rec at ',' into itab2-matnr
                               itab2-werks
                               itab2-quant.
    append itab2.
    endloop.
    That's it.
    Regards,
    Rich Heilman
    Message was edited by: Rich Heilman

  • Best way to read a file

    Hi All,
    I'm curious to know what is the best (fast) way to read a binary file. In particular, I'm thinking if using a BufferedInputStream I can obtain better results.
    In my opinion the FileInputStream class should be already optimized to read bytes from the underlying OS so that using BufferedInputStream I should not have benefits.
    If this is true, FileInputStream.read() should have the same performances of FileInputStream.read(byte[]).
    Is it correct ?
    ste

    what I expect for 1 is the FileOutputStream collects all bytes in a buffer calling OS when the buffer is full or if flush() is called. I don't think all the difference (30s vs 100ms) is since method invocations overhead.That's not what it does. It has no built in buffer, as far as I am aware.
    I created this test to test the cost of method overhead. This is using read(), but could be changed to use write. It shows definite performance effects to doing single reads repeatedly on a 5 meg byte array input stream (as opposed to one read) but nothing that's going to compare to reading latency from an actual file
         public static void readTest() {
              byte[] vals = new byte[5000000];
              for (int i = 0; i < vals.length; i++) {
                   vals[i] = (byte)(i % 256);
              ByteArrayInputStream in = new ByteArrayInputStream(vals);
              long time1 = System.currentTimeMillis();
              for (int i = 0; i < vals.length; i++) {
                   in.read();
              long time2 = System.currentTimeMillis();
              in = new ByteArrayInputStream(vals);
              try {
                   int got = in.read(new byte[5000000]);
                   System.out.println("got: " + got);
              catch (IOException iox) {
                   iox.printStackTrace();
              long time3 = System.currentTimeMillis();
              System.out.println("read each: " + (time2 - time1));
              System.out.println("read batch: " + (time3 - time2));
         }

  • Recommended way to open a text file included in a jar?

    Forgive me if this seems like an ignorant question, but I keep reading two different things about loading resources in the javadocs and forums, and can't seem to connect them...
    Say you want to open a text file and read the contents into a String or a List. Apparently, the preferred way to do this is something like:
    fileName = "myFile.txt";
    BufferedReader br = new BufferedReader(new FileReader(new File(fileName)));
    String line;
    while ((line = reader.readLine()) != null) {...}
    Now say you want to distribute your app in a jar file, with the text file included in the jar file. The above method won't work, because a FileReader operates on a File, and as I understand it, once myFile.txt is packed into the jar file, it's no longer a "file".
    So what do you do? I keep reading that the best way to open the jarred text file is to use something like this:
    InputStream is = getClass().getResourceAsStream(fileName);
    Here's where I get confused: InputStream, and all of its subclasses, are now supposedly dispreferred for reading character data (in preference to Reader, as above). But no subclass of Reader can wrap around an InputStream, which would facilitate the reading of character data greatly, with methods like readLine().
    So my question is: What's the best way to read a text file from within a .jar?
    Thanks,
    Gregory

    great! glad it's working
    here is a statement from the javadoc
    http://java.sun.com/j2se/1.4.2/docs/api/java/io/InputStreamReader.html
    For top efficiency, consider wrapping an InputStreamReader within a BufferedReader. For example:
    BufferedReader in
    = new BufferedReader(new InputStreamReader(System.in));
    kind regards
    Waken16

  • Read a zip file from Application server.

    Hi,
    Is there a way to read a zip file from the applicatoin server to internal table in ABAP program?  The operation system is running MS windows server.  The zip file contains only 1 text file.  I tried to use open dataset 'uncompress', and use read dataset, but read dataset gave me sy-subrc = 4.  Any feedback is greatly appreciated.
    Thanks.

    hi,
    to convert xstring to text you can use this:
    DATA unzipped_data TYPE xstring.
    DATA text_data TYPE string.
    DATA conv_x2c TYPE REF TO cl_abap_conv_in_ce.
    conv_x2c = cl_abap_conv_in_ce=>create( ).
    conv_x2c->convert( EXPORTING input = unzipped_data IMPORTING data = text_data ).
    moreover, if you want to split your text at "end of line" (CR LF in microsoft windows) into lines:
    DATA text_lines TYPE TABLE OF string.
    SPLIT text_data AT cl_abap_char_utilities=>cr_lf INTO TABLE text_lines.

  • Java mapping - for reading the binary file contents and changing filename

    Hi,
    I have already gone through the various bolgs and threads and have not been able to find a solution to my problem.
    One blog did give some idea but did not help- "JAAPPING", an alternate way of reading a CSV file
    I am not very good in java but have been trying some out recently to fulfill the interface requirements.
    I would really appreciate if you could help am I am giving below the detailed scenario below.
    Part 1- working fine - The incoming file looks like:
    :20:STMEMU096868DUBE
    :25:001180256210
    :28C:00371/00001
    :60F:C090617AED742136,92
    :61:0906300630CD34,27FINTCREDIT INTEREST
    26MAY2009 TO 25JUN2009
    :62F:C090630AED742171,19
    :64:C090630AED742171,19
    The file name as received is:TCDE.BLQSAM.SAEA2682.C0084025.A9G24T58.20090724195908
    This file without any conversion is placed on XI server dircetory folder.
    Part 2 - need to develop
    The file should now be renamed according to the incoming value in 2nd line - specifically the 12 digit value 001180256210 and placed on the R/3 dircetory folder.
    The new file name in the above example should be:
    AC_NO_001180256210_datetime
    The module for the above was created and the last time I checked it was working.
    However, when I wanted to do final testing in Dev and move the changes further, the module has seemed to have stopped working so I need an alternate solution fast.
    I was thinking of doing the Java mapping as I will be more in control as to what is going on thereby reducing the dependency.
    There is no need to create any target xml structure as the file as it is needs to be placed in the target folder with a new name.
    I can get the file name in UDF which I have already created but i am not usre if it working.
    Can you please help?
    Any help will be greatly appreciated.
    Regards,
    Archana
    +44-7867636863

    Hi Stephen
    The xml must be getting added in the below part of the code. It is coming from arg[0]
    You can put a check and get it removed.
    while ((len = arg0.read(buffer)) != -1) {
      arg1.write(buffer, 0, len);
    Regards
    Osman

  • Read from a file continuously

    Hello all.
    I wonder if there is an easy way to read from a file so that the currect contents of the file are always available within a Java program.
    For instance:
    1. The file "text.txt" has one line: "hello"
    2. Open the file from a Java program; it has the line "hello"
    3. Somebody adds another line to the file: "bye"
    4. The Java program is noticed about 3. so that the line "bye" can be read
    Something like "tail -f" or a named pipe (fifo) in Unix.
    Thanks in advance.
    God bless,
    Jaime

    No, this is NOT a solution. Once FileReader has encountered an EOF condition once, it will never go back to the file descriptor to see if there might be some more available. (For that reason, also reader.ready() will never return true again, no matter how much is appended to the file.) I tried this on Java 1.5.0_11 on Solaris.
    The other proposed solution, checking the file length periodically using the File length() method and then re-opening the file if the length is different, is also seriously flawed for several reasons:
    (a) If the file is renamed, you have no way of telling whether the file you already opened is modified -- the next time you call file.length(), it would fail since the old name doesn't exist any more, or, even worse, if meanwhile a new file was created under the old name, you'd be looking at a different file, not the one you've opened for reading!
    (b) If you do detect a change, having to reopen the file as a RandomAccessFile to be able to seek to the last read position is bad because you have to implement your own buffering (can't wrap BufferedReader around it, obviously), AND it suffers from the same file rename problem! The file you re-open might be a different one, so seeking to the last read position would land you at an arbitrary spot in a different file, and you wouldn't even know it!!!
    As a conclusion, it is apparently not possible to implement something as elementary as "tail -f" in Java correctly!
    Someone will have to think about that. Yes, I saw the argument that this may not be implementable on ALL kinds of file systems and hence not portable, but just because Windows file handling is broken, this shouldn't mean that Java file handling has to be broken on all decent platforms as well!
    :-(

  • Reading huge flat file in OSB 11gR1

    Hi,
    I want to read a flat file in OSB.The size of the flat file may be larger, upto 1 MB.
    As per my knowledge, OSB provides following approaches to read a flat file-
    1.JCA(creating a file adapter in jdev and importing artifacts in OSB)
    2.MFL transformation
    3.Java callout
    Please let me know which is the best way to read the flat file.Also , is there any other way to do the same.
    Thanks in advance.
    Regards,
    Seemant
    Edited by: Seemant Srivastava on Feb 18, 2011 1:47 PM

    Which option is best one to convert a flat file to XML - is it via File Adapter or MFL ? Well, it's a topic of debate and it usually depends on your choice. Manoj has explained it clearly above that why one may prefer File Adapter over MFL. It also depends on your familiarity with the product. If you are a Oracle developer dealing with BPEL/Mediator mostly then you will prefer going for File adapter in this situation, even with OSB, but if you are a OSB developer (since the time it was known as ALSB) you will prefer MFL over adapter.
    It's just matter of choice & your comfort. Remember, in different-different cases, both solutions may result in different performance, so better test them from performance perspective and then choose.
    Such flexibility of optional tags can only be handled by mfl.I don't think so. File adapter should also be able to handle this use case. Have you checked this -
    http://download.oracle.com/docs/cd/E17904_01/integration.1111/e10231/nfb.htm#CHDDHEAI
    Also, upto what size of input file is supported by mfl.It's a unanswerable question. It totally depends upon your system structure. I personally don't prefer huge files translation at OSB because it hurts the performance of OSB.
    but I think such feature will not be supported when the file adapter artifacts are imported and used in OSB 11.1.1.3/11.1.1.4Correct. From OSB Dev guide -
    25.2.1.1 Oracle JCA Adapter Limitations
    Following are limitations when using some JCA adapters with Oracle Service Bus:
    •Oracle JCA Adapter for AQ – Streamed payload is not supported with Oracle Service Bus.
    •Oracle JCA Adapter for FTP and Files – Attachments (large payload support), pre- and post-processing of files, using a re-entrant valve for processing ZIP files, content streaming, and file chunked read are not supported with Oracle Service Bus.
    http://download.oracle.com/docs/cd/E17904_01/doc.1111/e15866/jca.htm#BABBICIA
    Regards,
    Anuj

Maybe you are looking for

  • Can I overwrite a playlist on my computer using a second ipod?

    I have had no issues on my itunes using windows 7, I was synching a playlist I listened to of just my checkmarked music.  For no reason I could see, about 2 weeks ago, my itunes on my desktop locked up during a sync of my iPhone.  I didnt think much

  • Internet Explorer 7 and Zen Media Explo

    Does the final version of Internet Explorer 7 still break Zen Media Explorer? There were posts saying that the Beta version broke it. I keep telling auto update to not install IE7, because I never use IE for web surfing. Thanks. Does anyone have any

  • Material Price cannot be deterimied

    Hi, Good day to all, I want to do external purchase of some components via a PM order. So I've created a PM order and entered the material in Components tab with Item Category = N (non stock) and entered all the required information for purchasing. B

  • Can you use the iPod connector cable to charge the iPhone or

    only the cable that came with the iPod? Also, I put the iPhone briefly into my old inMotion speakers and a message came up saying that the device didn't support an iPhone and would either not charge my iPhone or have bad consequences for my iPhone-i

  • Bug? - CS5 Spacebar Activates Bird's eye View - Graphics's Card Recommendation?

    Hi, Overall I'd say that the OpenGL is improved in CS5 over CS4, although I have this disruptive bug. Sometimes I hit the spacebar to move and the bird's eye view is activated instead. My Nvidia GTX 260 driver is up to date. Photoshop is also updated