To read line in the file

hi,
i wanted to know how to read the file line by line.after it reaches ther last line it has to start from the first line.. can u please help me out in this

import java.io.*;
class ReadTextFile
public static void main ( String[] args )
   String fileName = "yourtextfilehere.txt" ;
   String line;
   try
     BufferedReader in = new BufferedReader(
         new FileReader( fileName  ) );
     line = in.readLine();
     while ( line != null )  // continue until end of file
       System.out.println( line );
       line = in.readLine();
     in.close();
   catch ( IOException iox )
     System.out.println("Problem reading " + fileName );
}

Similar Messages

  • How can we read some bytes from every line of the file

    How can we read some bytes from the every line of the file moving on to the next line
    without using the read line

    Actualiy readLine() takes more execution time
    for reading a part of line if we can do so without
    readLine() we can save some time...Well, if you knew, beforehand, the length of each line, you could use RandomAccessFile and its seek method, but, since you don't, you would have to read the rest of the line character-by-character, checking to see if it is a newline, in order to place the "cursor" at the beginning of the next line in order to read the next few characters you want.
    So, as you can see, you will need to read the entire line anyway (and if you do it yourself you also have to do the checking yourself considering all three possible end-of-line sequences), so you just as well use readLine().
    Some people may suggest Scanner and it's nextLine() method, but that also needs to read the rest of line (as evidenced by the fact that it returns it), so that is no different than the readLine() (or read it yourself) solution.

  • When I open up an e-mail attachment a box pops up PRINT TO FILE below that line OUTPUT FILE NAME with an empty line for the file name vs. simply going to my default printer?

    when I open up an e-mail attachment a box pops up PRINT TO FILE below that line OUTPUT FILE NAME with an empty line for the file name vs. simply going to my default printer?

    Make sure that '''''Print to File''''' isn't selected in the native print dialog box ''(see screenshot below)'' middle-right, and make sure your Printer is selected at the top of that dialog box.
    ''I'm a little confused why an email attachment would need to go directly to the printer, but that's what you asked about.''

  • Lines in the file when I scan with the ADF in the Image Class MF4770

    Hi.
    I am the owner of a Mulifunction Printer Canon MF4770 Image class.
    When I scan a document using the ADF, I get two lines along all the page digitalized.
    Is there any way to clean the ADF scaner?
    why do i get this line in the file ?
    I attached an example in order to you can see what I'm  trying to explain.
    Regards

    [topic moved to Reader Touch subforum]

  • How to count the total lines of the file (including the file header)

    Hi all,
    I am working with Idoc to file scenario(FCC).
    I need to map one of the field with a recound count ie.., count of the total lines of the file (including the file header).
    Eg:Record Count-- mapping area:Total number of records in the file including file header     The total line of the file (including the file header).
    Can i get a help on this.
    Thanks and Regards,
    Manoj

    Hi !
    If there is a tag of your IDOC that occurs the same quantity of times as file lines you have to create in your target file, you could make a Java user defined function in graphical mapping that "caches the entire queue" (use the corresponding option button), that receives as input that field of the IDOC, and returns the "lenght" (.length property value) of that input parameter (it is an array) as output..that should be the file line quantity..you may also add 1 to that count, for the header.
    Hope it helps.
    Regards,
    Matias.

  • Read lines from a file

    With "ApartmentFileHandler" I can write Apartment-objects to a file and read them from a file.
    To write I loop through each room in the apartment and write its size
    and type. I put 1 Room per line.
    To read I read each line of the file and recreate the room stored
    there. When there are no lines left in the file I pass the Rooms from
    the file to the Apartment constructor and return the new Apartment.
    Only one Apartment is stored in each file. (Apartment doesn?t implement
    Serializable, so I cant write straight Apartment-objects to a file.)
    So in the file, there are stored one "Room" per line: String type,
    double size
    QUESTION: How am I able to read all lines: first line first -> make a new room of
    it, and store to a roomArray? Then second -> do same as I did to the
    first.
    Now my read()-method doesn't read all lines. How to change it to read next line?
    Thanks in advance.
    public class Room extends Space
    public Room(String type, double area)
    public String getType()
    public double getSize()
    public class Apartment extends Space
    public static final String KITCHEN
    public Apartment(Room[] rooms)
    public String getType()
    public double getSize()
    public Room[] getRooms()
    public class ApartmentFileHandler extends Object {
         private FileOutputStream ostream;
         private ObjectOutputStream op;
         private FileInputStream istream;
         private ObjectInputStream ip;
         private String filepath;
    public ApartmentFileHandler (String filepath) {
                              this.filepath = filepath;      
    public Apartment read()
                                      throws InvalidApartmentFile,
                                                 IOException {
          istream = new FileInputStream(filepath);
          ip = new ObjectInputStream(istream);
                                  // count how many rows in the file ie. rooms
                           String lineThatIsRead = ip.readLine();
                           int count =0;                                             
                           while (lineThatIsRead != null) {
                                    count =count +1;
                                    lineThatIsRead =ip.readLine();
         Room room;
         Room roomArray[ ] = new Room[count];
          for(int i =0; i<count; i++) {
                                  String type  =ip.readUTF();
              double size =ip.readDouble();
                                   room =new Room(type, size);
              roomArray[ i ] =room;
                                Apartment apartment = new Apartment(roomArray);
                                return apartment;
            public void write(Apartment apartment)
                  throws IOException {
                    ostream = new FileOutputStream(filepath);
                    op = new ObjectOutputStream(ostream);
                    int numberOfRooms =apartment.getRooms().length;
                    Room[] allRooms =apartment.getRooms();
                    for (int i=0; i< numberOfRooms; i++) {
                         op.writeUTF( allRooms[ i ].getType() );
                         op.writeDouble( allRooms[ i ].getSize() );
                         op.writeChars("\n");

    Hi,
    I recommend using java.io.BufferedReader in conjunction with java.io.FileReader:
    BufferedReader reader=new BufferedReader(new FileReader(filepath));
    java.io.BufferedReader provides the method public java.lang.String readLine() throws java.io.IOException which lets you read a complete line from the underlying java.io.Reader object. Furthermore, BufferedReader will - as the name implies - buffer your IO-operations which will help you improve the program's performance. In order to read all the lines contained in a text file you might want to apply a loop:
    String line;
    while((line=reader.readLine())!=null && line.length()!=0){
    //process data in string line (parse into string and double)
    Of course, everything must be contained within a try-catch-block in order to be able to handle upcoming IOException objects.
    Regards,
    Michael

  • Read lines from text file to java prog

    how can I read lines from input file to java prog ?
    I need to read from input text file, line after line
    10x !

    If you search in THIS forum with e.g. read lines from file, you will find answers like this one:
    Hi ! This is the answer for your query. This program prints as the output itself reading line by line.......
    import java.io.*;
    public class readfromfile
    public static void main(String a[])
    if you search in THIS forum, with e.g. read lines from text file
    try{
    BufferedReader br = new BufferedReader(new FileReader(new File("readfromfile.java")));
    while(br.readLine() != null)
    System.out.println(" line read :"+br.readLine());
    }catch(Exception e)
    e.printStackTrace();
    }

  • Can the folder C:\Windows\Cache\Adobe Reader 6 and the files it contains simpley be deleted?

    My daughter is running Adobe Reader 9.4.5 and Adobe Flash Player 10 Active X
    on a Dell Dimension 4400 system with
    Windows XP Home Edition version 2002 Service Pack 3.
    During a full system backup using Seagate DiskWizard version 11.0.8326
    each time folder C:\Windows\Cache\Adobe Reader 6
    is accessed the pc freezes with the Blue Screen error
    IRQL NOT LESS OR EQUAL ERROR 0x0000000A
    (0x00000166, 0x00000002, 0x00000000, 0x804E5443).
    Each time the Adobe Reader 6 folder is opened manually, the system presents a spinning
    CD icon superimposed on the cursor and attempts to access the CD drive.
    The access ultimately fails since there is no CD loaded because there is no intent to install
    anything at the moment.
    Through a manual process of backing up each of the the files in the Adobe Reader 6 folder
    individually, one at a time, I strongly suspect the problem file to be instmsiw.exe.
    Can the folder C:\Windows\Cache\Adobe Reader 6 and the files it contains simpley be deleted? 
    Are there any registry entries or issues that must be addressed before deleting these files?
    What is the best way to free up space on the C drive that is apparently being occupied by
    files left over from the install of a prior version of Adobe Reader?
    The folder C:\Windows\Cache\Adobe Reader 6 contains the following files:
    0x0409.ini                        5KB          Configuration Settings        2/18/2003
    abcpy.ini                          2KB          Configuration Settings        3/24/2003
    Adobe Reader 6.0.msi      2198KB     Windows Installer               5/19/2003
    Data1.cab                       23334KB    WinZip file                         5/19/2003
    instmsia.exe                   1669KB      Application                        3/11/2002
    instmsiw.exe                  1780KB      Application                        3/11/2002
    Rdr60ENU.itw                 16KB          ITW file                            5/11/2003
    Rdr60ENU.mst               4KB            MST file                           4/16/2003
    Setup.exe                      212KB        Application                        5/19/2003
    Setup.ini                        2KB            Configuration Settings        5/19/2003
    Thank you for any assistance you can provide.

    Go to Add/Remove Programs in Control Panel and uninstall Adobe Reader 6. That version poses a security risk to your system and should be removed a.s.a.p.
    After you remove it, reboot and then delete the "Adobe Reader 6" folder at the location you mentioned above.
    Then go to http://get.adobe.com/reader/direct/ and download version 9.4
    After that installs, download the latest patch for it by opening the program, then go to Help | Check For Updates.
    As a precaution, download the free version of Malwarebytes from here: http://www.malwarebytes.org/products/malwarebytes_free and then run a full system scan.

  • Read and List the Files from Remote Webserver Path

    Hi All,
    I have requirement where i need to Read and List the files from a Folder of Remote webserver path using JAVA.
    Remote webserver is within the network only...No Firewall and also Access is given to Read the folder. No Issues on this.
    Folder will just contain some PDF files...
    I just need to display the PDF file names available in the Folder..
    No need to read the PDF File...Only required to read the folder to list the file names in it.
    Looking forward some workaround to this.
    Thanks and Regards.

    I need to read the folder from a webserver path of different machine...
    File dir = new File( prop.getProperty("inputPath"));
    File[] files = dir.listFiles(fileFilter);     
    final String match=siteName;
         final String type=reportType;
         Calendar c1 = Calendar.getInstance();
         c1.add(Calendar.MONTH, - Integer.parseInt(prop.getProperty("filterMonths"))); //Filters reportes generated in last X months (X picked from config file)           
         final long filterDate = c1.getTime().getTime();           
         FileFilter fileFilter = new FileFilter() {
         public boolean accept(File file) {
         long fileLastModiDate = file.lastModified();      
         if((fileLastModiDate >= filterDate) && (file.getName().toLowerCase().startsWith(match)) && ( (type.equals("M") && file.getName().indexOf("WIP")==-1) || ((!type.equals("M") && file.getName().indexOf("WIP")!=-1)) ) ) {                        
              return true;
         }else {
              return false;
    Here it works fine if the input path is local machine..
    But i need to know how to give the input path as WEBSERVER PATH of different machine??

  • Can't save the illustration.  The file may be read only, or the file is in use by another applicatio

    Getting error "Can't save the illustration.  The file may be read only, or the file is in use by another application."  The file is not read only and is not in use by another application.

    The same thing may happen in Windows Explorer, specifically if it is a very big file (physical size), so preparing the preview may take a lot of time.
    In that case it is used by "another application", that is: Explorer.
    By the way, which version of Illustrator are you using, Tetons?

  • I purchased an audio book from I tunes but when I sync with my I phone it respond with error saying could not read or write the file. It only sync parts 2

    I purchased an audio book from I tunes but when I sync with my I phone it respond with error saying could not read or write the file. It only sync parts 2

    Those videos are probably not in an iPod-friendly format. It’s picky about that. You can try converting them, if possible.
    As for the audiobooks, are you sure they haven’t synced? You’ve enabled it to sync books and checked the “Audiobooks” section of your iPod?

  • Have a very large text file, and need to read lines in the middle.

    I have very large txt files (around several hundred megabytes), and I want to be able to skip and read specific lines. More specifically, say the file looks like:
    scan 1
    scan 2
    scan 3
    scan 100,000
    I want to be able to skip move the filereader immediately to scan 50,000, rather than having to read through scan 1-49,999.
    Thanks for any help.

    If the lines are all different lengths (as in your example) then there is nothing you can do except to read and ignore the lines you want to skip over.
    If you are going to be doing this repeatedly, you should consider reformatting those text files into something that supports random access.

  • How to add new line to the file?

    Hello,
    I will like to print 2 line of string in the following format to the
    file:- file.txt
    String1
    String2
    How to print a new line after String1 so that String2 can be written after String1?
    - Eugene -

    Do you mean...
    PrintWriter pw=new PrintWriter(new FileOutputStream("file"));
    pw.println(string1);
    pw.println(string2);
    pw.close();
    the println puts a new line after string1.

  • Adobe reader not open the file immediately after saving it  with Microsoft Office

    I have an older version Adobe Reader 9, and worked fine until today. I did the upgrade to Adobe Reader XI (11.0.06).
    I have Window´s Office 2010 on my computer. When I save a document on *pdf file, Adobe starts automatically and open the document (Open file after publishing.) After the upgrade, documents are not open automatically and shows the next message:  "There was an error  during initialization. An internal error ocurrred." and  "There was an error opening this document. Access denied.". But if I try manually, files are open. How do I fix this problem.

    I'm having a similar issue.  The .pdf files open fine locally, but when I put them up online, they will not open and I get the same error message.  If I download and save the files, they show a 1KB file size instead of 168KB.
    Drive space is not an issue (looking at over 225GB of free space on the main drive).
    In searching on-line, the main cause I am finding is receiving the file via e-mail and a decoding issue.  This is not the case with these files as they were created on my machine and uploaded using Filezilla to the server.  I'm using Acrobat Pro 7.0 on a windows box running Vista Ultimate.
    Any ideas on what would be causing this issue?

  • How to write a function read line from a file in FDK?

    Hello,
    I want to write a function that can read a file in line by line in FDK. How do I write it. If FDK could not. Is there any the way? Please help.
    Thank you,
    Thai Nguyen

    Thai,
    You can use the "channel" functions for this. I'm far from an expert on channel programming but I've read files line-by-line successfully by going one character at a time, looking for a carriage return.
    You can open up the file channel with something like:
      ChannelT chan;
      FilePathT *path;
      UCharT ptr[1];
      IntT numRead;
      path = F_PathNameToFilePath("C:\\temp\\mydoc.txt", NULL, FDefaultPath);
      if((chan = F_ChannelOpen(path,"r")) == NULL)
          return;
      //read the first character
      numRead = F_ChannelRead(ptr, sizeof(UCharT), 1, chan);
    ...then you can call F_ChannelRead iteratively to build the string in a buffer, looking for a carriage return (ASCII 13) and stopping there. (that is, ptr[0] == 13).
    There might be a better way. This is just the way I've gotten it to work. It probably is not a good method for unicode files.
    Russ

Maybe you are looking for

  • Siri is not working on my new iPad Air

    Siri isn't working on my week old iPad Air.  I've turned it off and on and sync'd it several times but no joy.  Any help will be appreciated.

  • Linux installation in SuSE 10.2

    Has anyone been able to get LabVIEW 8 to work on SuSE 10.2? Signs of success or pointers would be welcome. I do not understand the need for LabVIEW to run such an ancient version of the Mesa libraries. The lib this is trying to use dates to 1999 or s

  • Error formula SUMCT with drill across.

    Hello everyone, I have a problem with the formula SUMCT. A formula has been defined applying the SUMCT operator to the 0???? index 0DEB_CRE_LC. The 0COSTELMNT characteristic is on the query rows, and a hierarchy is active on the cost element. When th

  • Problem with phpMyadmin IFRAME in Safari

    hi there, This is how phpMyadmin shows in Safari. the IFRAME isnt resizable making the table list impossible to read [IMG]http://i37.tinypic.com/mscgif.png[/IMG] Anyone know how to fix this or is this a Safari bug? It shows up beautifully in Firefox

  • Can I use the "Private browsing" mode on mobile?

    Can I use the "Private browsing" mode on mobile?