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

Similar Messages

  • 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

  • What's the best way to read JSON data?

    Hi all;
    What is the best way to read in JSON data? And is the best way to use it once read in to turn it into XML and apply XPath?
    thanks - dave

    jtahlborn wrote:
    without having a better understanding of what your definition of "use it" is, this question is essentially unanswerable. Jackson is a fairly popular library for translating json to/from java objects. the json website provides a very basic library for parsing to/from xml. which one is the "best" depends on what you want to do with it.Good point. We have a reporting product ([www.windward.net|http://www.windward.net]) and we've had a number of people ask us for JSON support. But how complex the data is and what they want to pull is all over the place. The one thing that's commin is they generally want to pull down the JSON data, and then put specific items from that in the report.
    XML/XPath struck me as a good way to do this for a couple of reasons. First it seems to map well to the JSON data layout. Second it provides a known query language. Third, we have a really good XPath wizard and we could then use it for JSON also.
    ??? - thanks - dave

  • This community is great -- very helpful. What is the best way to read "word" docs on my brand new iPad 2? Is there an app for that?

    This community is great -- very helpful. What is the best way to read "word" docs on my brand new iPad 2? Is there an app for that?

    If you're just reading them from email attachments, you can just open it to "view" the document.
    However, if you wish to do editing and work, you'll need an application. I use Documents to Go, but there are other versions that people are happy with - do a search in the App store for "office suite" or "word processing".
    The next challenge is getting docs back and forth. Doc2Go and others have their own ways to physically sync docs when connected to a computer; you can also email changed/revised/new documents from the iPad to yourself. However, I use a "cloud service" called DropBox that stores docs in the cloud (so I can get to them anywhere) - I paid for the Premium version of Docs2Go to allow that kind of syncing.

  • 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
              

  • Using the new iPad, what's the best way to watch video files (away from home) which are stored on a NAS (WD My Book Live)? Any help would be appreciated!

    Using the new iPad, what’s the best way to watch video files (away from home) which are stored on a NAS (WD My Book Live)?  Any help would be appreciated!

    Before you go, move the files to I tunes and sync them down.  There is no viable way to stream from your nas drive to the pad.

  • What's the best way to removed unwanted files?

    I have an iMac G4 running OS X 10.4.11 with 1GB of DDR SDRAM. I'm wondering what's the best way to remove unwanted files from the RAM, if it's even possible. There are apps and other files I no longer need. If I can dump the unused files will it help the computer run a little faster? Can I eliminate the unwanted files some how by myself or do I need a program that does it? Thanks

    bad dad wrote:
    I have an iMac G4 running OS X 10.4.11 with 1GB of DDR SDRAM. I'm wondering what's the best way to remove unwanted files from the RAM, if it's even possible. There are apps and other files I no longer need. If I can dump the unused files will it help the computer run a little faster? Can I eliminate the unwanted files some how by myself or do I need a program that does it? Thanks
    Applications are stored perminately on the harddrive [ Macintosh HD ]. When applications are running that is when they appear in a window, they take up RAM. You see your running applications by using activity monitor:
    Macintosh-HD -> Applications -> Utilities -> Activity Monitor
    Application when they are not running, they do not take up RAM.  You will not see any performance improvement when you delete an application from your Harddrive.  [ unless you have filled up your harddrive ]
    Best to have greater than 2gig of free space on your Harddrive.  Many posters to these forums state that you need much more free space: 5 gig to 10 gig or 10 percent of you hd size.
    Most applications do not take up much space on the Harddrive.  I copy my unused application to a folder named additional applications.
    (0)
    Be careful when deleting files. A lot of people have trashed their system when deleting things. Place things in trash. Reboot & run your applications. Empty trash.
    Go after large files that you have created & know what they are.  Do not delete small files that are in a folder you do not know what the folder is for. Anything that is less than a megabyte is a small file these days.
    (1)
    Run
    OmniDiskSweeper
    "The simple, fast way to save disk space"
    OmniDiskSweeper is now free!
    http://www.omnigroup.com/applications/omnidisksweeper/download/
    This will give you a list of files and folders sorted by size. Go after things you know that are big.
    (2)
    This will save you a gig of space.
    Monolingual is a program for removing unnecessary language resources from Mac OS X,in order to reclaim several hundred megabytes of disk space. It requires at least Mac OS X 10.3.9 (Panther) and also works on Mac OS X 10.4 (Tiger). It worked for me on 10.4
    http://monolingual.sourceforge.net/
    A detailed write-up on how to use Monolingual:
    http://www.jklstudios.com/misc/monolingual.html
    (3)
    These pages have some hints on freeing up space:
    http://thexlab.com/faqs/freeingspace.html
    http://www.macmaps.com/diskfull.html
    (4)
    Buy an external firewire harddrive.
    (5)
    Buy a flash card.

  • 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

  • What is the best way to keep your files organised

    I would like to know what is the best way to keep your file organise when I am
    Loading program's like numbers and pages from iPhone to MacBook i alway 
    Get double of the same work sheet

    I would like to know what is the best way to keep your file organise when I am
    Loading program's like numbers and pages from iPhone to MacBook i alway 
    Get double of the same work sheet

  • What is the best way to run .exe files on my mac?

    What is the best way to run .exe files on my mac? I need to run some updates for my john deere gps and the downloads i get can only be run on windows.

    There are several options for running Windows software (*.exe files) on a Mac, depending what your program is, how often you use it, and your personal preferences.
    One way that does not require Windows is an open source effort called WINE.  Check out winehq.org.  You may find that that's all you need for your programs.  There is also a commercial effort that has grown from WINE, and you will find info about it on the site mentioned.  These DO NOT require that you have and install Windows.
    If you want to run sessions devoted only to Windows software, and want programs to run as fast as they do on a PC, the Apple's Bootcamp program is useful.  With it you dedicate a partition on your hard disk to windows, and on startup choose to either boot into OS X or Windows.  Each runs without any connection to the other.  This requires you have a copy of the Windows software as well as the applications you want to run. 
    If you want to be able to easily exchange data between your Windows and Mac programs, and skip back and forth between the two, there are several emulators available that run on Mac OS X and create a Windows environment where many Windows programs can operate along side Mac programs.  Parallels and VMwear are two comercial packages available for purchase and Virtual Box is an open source effort available for free.  Google will find all three for you.
    My only experience is with Virtual Box.  It is slow and a bit clunky, but it is free and meets my needs for the very few "just got to have" windows programs I sometimes use.
    Google is your friend on this and can provide a lot more, and better, information than I can.
    Best of luck,
    Ray

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

  • What is the best way of reading a browser cookie and writing to sessionbean

    Hi,
    So far I have happily written a cookie in the visting browser and happily can display with a browser using a servlet println etc
    But what is the best way to take that value and put it into say getSessionBean1().setCookieValue("Cookievalue");
    I was thinking on the lines of calling a forward from the servlet "nexpage?cookievalue=stringetc".... or is there some nicer way?
    Thanks
    James

    In the page I simply referenced the facescontext directly... no need for a custom servlet.
    public void createcookie() {
    FacesContext fc = FacesContext.getCurrentInstance();
    HttpServletResponse resp = (HttpServletResponse)fc.getExternalContext().getResponse();
    Cookie userCookie = new Cookie("cookiename", "cookievalue");
    userCookie.setMaxAge(-1);
    userCookie.setMaxAge(3600);
    resp.addCookie(userCookie);
    return null;
    public String readcookie() {
    FacesContext fc = FacesContext.getCurrentInstance();
    ExternalContext ec = fc.getExternalContext();
    Map cookiemap = ec.getRequestCookieMap();
    if (cookiemap != null) {
    Cookie cookie = (Cookie) cookiemap.get("cookievalue");
    return cookievalue;
    For reference I could not get getCookies() method of HttpServletRequest to work.. it would only return JSESSIONID.

Maybe you are looking for

  • Transferring files to a new computer

    I have both an IPOD 20G and a Nano. On my old computer, the Nano is its own playlist within my library. I got a new computer and want to transfer files for both. I have so many songs that I do not wish to burn them all on cds and reload. Not all of m

  • Switching back and forth between keys on vocal track

    I followed the instructions in the garage band tutorial for changing key (pitch?) of a vocal track for part of the project. Doesn't seem to work the way they suggest - calling up master track, adding a point on the automation line where I want change

  • Premiere pro hangs on waving a mouse over a clip thumbnail

    This problem has been going on for months. I cannot keep taking enforced 5 minute breaks. Premiere hangs when waving a mouse over a thumbnail in a bin. The entire machine becomes unresponsive for up to five minutes. Hover Scrub is not switched on. Th

  • How do I remove the header/footer when printing from ipad safari?

    I'm trying to print invoices from a web app I'm using in safari on my ipad1. When I print there doesn't seem to be anyway not to include the header and footer that prints by default with Safari. I'd rather not have to use a second app just to print a

  • Help...with a friend...need assistance

    Hey everyone. A new mac user friend has accidentally dropped 1900 photos from a usb key drive into the desktop and I have the beachball of death on the screen with these icons/photos loading. I want to stop the process and cannot find a way to start