Best way to read in File of characters...

I have a file whose size is roughly 16k-20k.
I need to read in the file and perform some logic based on each character of the file.
Is wrapping a FileReader within a BufferedReader the most efficient way to do this? Or is there some nio package or custom buffer stuff I can do to speed it up?
thanks

I gues if you have to check the charactars multiple times putting the file in a string or
stringbuffer would be faster. If you read it only once you might use a bufferedreader.
I'm not verry experienced but think that the charset is importaint, here is some code
on how I red Japanese text. I changed the getBytes to create the string in ASCII.
          try{
               File f = new File("somefile");
               FileInputStream fi = new FileInputStream(f);
               byte[] buf = new byte[1024];
               int len;
               int i = 0;
               ByteArrayOutputStream bos = new ByteArrayOutputStream();
               while ((len = fi.read(buf)) > 0) {
                    bos.write(buf, 0, len);
               byte[] data = bos.toByteArray();
//               String dataString = new String(data,"ASCII");
               fi.close();
          }catch(Exception e){
               e.printStackTrace();
          }

Similar Messages

  • The best way to read properties file

    Hi folks,
    The best way to read properties file i.e.. using ResourceBundle or FileInputStream . if so how to do it , my properties file is n WEB-INF/classes/myprop.properties.It's urgent.
    Thanks & Regards,
    Rajeshwar.

    WEB-INF/classes should be in your classpath. The web container takes care of that.
    All you have to do is call ResourceBundle.getBundle("myprop").
    It'll append the .properties for you.
    http://java.sun.com/j2se/1.5.0/docs/api/java/util/ResourceBundle.html#getBundle(java.lang.String)

  • Best way to read text files at multiple production sites

    Need to write a solution to read txt files that contain binary data on multiple SQL Servers. I have no control over the SQL servers, they are not mine. Thinking of BULK INSERT or bcp. But must something on the server be turned on for it to work? What are
    some other production solutions for reading files and loading the data into a SQL table?

    Hello,
    I think the best way is create a SSIS package to import data into SQL Server tables. Here are some articles for your reference:
    http://codejotter.wordpress.com/2010/04/06/importing-multiple-text-files-using-ssis/
    http://technet.microsoft.com/en-us/sqlserver/dd941934.aspx
    Regards,
    Elvis Long
    TechNet Community Support

  • 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));
         }

  • What is the best way to read a file line by line?

    Hello, everyone!
    I want to read a file line by line, i.e. each time, a line of a text file is read and stored as a String object and the String object will be manipulated (parsed) later.
    I have found that FileInputStream does not have a function which is responsible for reading a line each time from a text file. Anyone have good suggestions?
    Best regards,
    George

    I always use the following example.. mayb that would help you as well
    File fid = new File(fileName);
    if (fid.exists())
            fr = new FileReader(fid);
            br = new BufferedReader(fr);
             while((txtstr= br.readLine()) != null)
    }

  • Which is theb best way to read a file of 5-10 mb

    Hi,
    I need to read a flatfile of 5-10 mb and simultaneously insert into database .
    Reading through FileInputStream or FileReader?
    Which is the best approach to do this keeping in considerataion performance and memory management.
    Please help .Its is an urgent task to be done.
    Thanks,
    kazim
    Message was edited by:
    kazimh

    I always use the following example.. mayb that would help you as well
    File fid = new File(fileName);
    if (fid.exists())
            fr = new FileReader(fid);
            br = new BufferedReader(fr);
             while((txtstr= br.readLine()) != null)
    }

  • What is the best way to read and manipulate large data in excel files and show them in Sharepoint

    Hi ,
    I have a large excel file that has 700,000 records in it. The excel file has a few columns that change every day.
    What is the best way to read the data form the excel file in fastest and most efficient way.
    2 nd Problem,
    I have one excel file that has many rows each row contain some data that has certain keywords.
    What I want is  to segregate the data of rows into respective sheets(tabs ) in the workbook.
    for example in rows have following data 
    1. Alfa
    2beta
    3 gama
    4beta
    5gama
    6gama
    7alfa
    in excel
    I want there to be 3 tabs now with each of the key words alfa beta and gamma.

    Hi,
    I don't really see any better options for SharePoint. SharePoint use other production called 'Office Web App' to allow users to view/edit Microsoft Office documents (word, excel etc.). But the web version of excel doesn't support that much records as well
    as there's size limitations (probably the default max size is 10MB).
    Regarding second problem, I think you need some custom solutions (like a SharePoint timer job/webpart ) to read and present data.
    However, if you can reduce the excel file records to something near 16k (which is supported rows in web version of excel) then you can use SharePoint Excel service to refresh data automatically in the excel file in SharePoint from some external sources.
    Thanks,
    Sohel Rana
    http://ranaictiu-technicalblog.blogspot.com

  • 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

  • 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!

  • Best way to read tracks of a MIDI file

    What is the best way to read events (sequentially based on time) of the tracks in a midi file ? Should they be read serially (track 0 all the way through then track 1, etc) or parallel based on some measure of time (of all tracks)?
    Edited by: yz2zy on Jul 24, 2009 11:18 PM

    Depends on what you're doing to it, I suppose.

  • What is the best way to safeguard my files and pictures before I send off my MacBook Pro to get fixed?

    What is the best way to safeguard my files and pictures before I send off my MacBook Pro to get fixed? I am running Mavericks and use an AirPort Time Machine to back-up all my files.

    Back up all data on the internal drive(s) before you hand over your computer to anyone. You need at least two independent backups to be completely safe. There are ways to back up a computer that isn't fully functional—ask if you need guidance.
    If privacy is a concern, erase the data partition(s) with the option to write zeros* (do this only if you know how to restore to an empty drive.) Don’t erase the recovery partition, if present.
    Keeping your confidential data secure during hardware repair
    Apple also recommends that you deauthorize a device in the iTunes Store before having it serviced.
    *An SSD doesn't need to be zeroed.

  • What is the best way to merge a file content into log file

    What is the best way to merge a file content into log file.
    In worst case, I will read the file line by line as string, then use
    logger.info(lineString)to output to log file.
    However, is there better way to do this?
    The eventual log file will be something like:
    log message 1
    log message 2
    content from file line 1
    content from file line 2
    content from file line 3
    log message 3
    log message 4Thanks

    John618 wrote:
    Thank you and let me explain:
    1. What do you mean by better?
    I would like to see better performance. read line by line and log each line as string can be slow. Did you measure this and determine that it is actually a problem for your application? Or are you guessing?
    Regardless of what you do you are still going to need to read the file.
    >
    2.The only better way I can think of is not having to do it, but I assume you have a very good reason to want to do this.
    Yes, I have to do it beacuse the requirement is to have that file content be part of logging.
    Any idea?How is it supposed to be part of it? For example which of the following is better?
            File AAA - contents
                       First Line
                       Second Line XXX
            Log 1
                    2009-03-27 DEBUG: Random preceding line
                    2009-03-27 DEBUG: First Line
                    2009-03-27 DEBUG: Second Line XXX
                    2009-03-27 DEBUG: Random following line
            Log 2
                    2009-03-27 DEBUG: Random preceding line
                    2009-03-27 DEBUG: ----- File: AAA -------------
                    First Line
                    Second Line XXX
                    2009-03-27 DEBUG: Random following lineBoth of the above have some advantages and disadvantages.
    The first in a mult-threaded app can end up with intermittent log entries in between lines, so having log lines with thread ids becomes important.
    The first can be created by reading one line at a time and posting one at a time.
    The second can be created by reading the entire file as a single string and then posting using a single log statement.

  • What is the best way to find a file on the servers disk without using web.xml?

              What is the best way to find a file on the servers disk without using web.xml?
              I want to find a configuration file not contained within the war file I have
              created. Is there a way to pass information into the ServletContext with out
              rebuilding the ear or war files? Tomcat 4.0 can do this in its server configuration
              files. Does BEA have the equivalent?
              Regards,
              Eric
              

    You can specify the path to the file as a system property
              eg
              java -Dconfig.file.location=./mydirecotry/myfile.txt com.test.MyApp
              "Eric White" <[email protected]> wrote in message
              news:[email protected]..
              >
              > What is the best way to find a file on the servers disk without using
              web.xml?
              > I want to find a configuration file not contained within the war file I
              have
              > created. Is there a way to pass information into the ServletContext with
              out
              > rebuilding the ear or war files? Tomcat 4.0 can do this in its server
              configuration
              > files. Does BEA have the equivalent?
              >
              > Regards,
              > Eric
              

  • What is the best way to name a file?

    What is the best way to name a file? Use "_" so that the characters make one, long name? Why do that?

    Another take on naming files, particularly image files, is like this:
    I use a file remaning application like Name Mangler to back, sequentially rename the photos.  I put them in a folder with a similar name.  Using the format I do, YYYY-MM-DD- Description-001.jpg, they are easy to sort by date by sorting alphanumerically.
    OT

  • Best way to stream MP3 files with ColdFusion

    I was looking for a kind of a built in player look in that
    all the user has to do is click and it will start playing within
    the browser. Some of the files are even 48MB long so if I can
    reduce that too that would be good. client goes on conferences and
    plan to record more conferences and we would like to host them on
    the site.
    Any Help?

    Making pod casts:
    http://www.podcastingnews.com/articles/How-to-Podcast.html
    http://www.windowsdevcenter.com/pub/a/windows/2005/04/05/create_podcasts_with_pc.html
    Flash players for MP3s:
    http://wimpyplayer.com
    Jukebox from
    http://swishzone.com
    --Nancy O.
    "Brandon" <[email protected]> wrote
    in message
    news:et99hk$svu$[email protected]..
    > I'm looking for recommendations about the best way to
    publish mp3 files.
    I
    > have a client that is a church that wants their staff to
    be able to upload
    > mp3 files on a weekly basis from a web client and have
    those files
    > automatically be included in a podcast feed as well as
    have a "play"
    option
    > and a "download" option. I know how to setup the front
    end . . . any
    > suggestions on the best way to implement this on the
    back end (such as
    > extensions or services)?
    >
    > --
    > Brandon
    >
    http://www.presentationsdirect.com
    >

Maybe you are looking for

  • Ver.9.5 The volume for file name cannot be found

    HI, My work Mac Book pro was recently upgraded to Mavericks from 10.6.8, with iPhoto 11 (ver. 9.5) also an included upgrade. One album of photos is no longer accesible - clicking on each thumbnail provokes the following window "The volume for <file n

  • HOT TO SET THE OUT PUT MESSAGE FOR PURCHASE ORDER

    As i was saving the Purchase order in Me21n the error message that came up was " NO OUTPUT MESSAGE SET FOR THE PO " HOW  DO I SET THE OUTPUT MESSAGE AND SET THE PO PRINT SETTING KINDLY HELP.

  • How to stop a process in a process chain?

    Hi I've got a process chain that calls several processes.  It's still running one of the processes but I want to stop the two that will run after (as it is now in the day time and they will impact on performance in our R3 system). I've looked on SM37

  • HACMP Clustering Script for SAP ECC 6.0 (SR1) - Automatic Failover-Oracle10

    Hello, I have installed the SAP ECC 6.0 (SR1) under AIX 5.3 / Oracle 10g with HACMP Clustering environment. Manual Failover is working fine. ASCS and Database instances are loaded in share drive with Virtual IP and Virtual name. Central Instance and

  • XI Rosettanet Adapater

    Hi, We are in the process of procuring XI and would appreciate help in the following areas. 1) We currently have a Business Connectors set up for a B2B application configured for a DMZ + Firewall Landscape. Can the XI be used similar to the Business