Want to know how to check for new line character in text file

Hi All,
I`m trying to read data from text file. However I`m not sure whether the data is in 1st line or nth line. Now I`m trying to read the text from the readline. But if text is "" and not NULL then my code fails. So I want to know how to check for new line character and go to next line to find the data. Please help.
Thanks
static int readandwriteFile(Logger logger,String filepath){
          BufferedWriter out = null;
          BufferedReader in = null;
          File fr = null;
          int get_count = 0;
          try     {
          if(new File(filepath).exists())
          fr= new File(filepath);
                    System.out.println("FileName: "+fr);
               if(fr != null){
in = new BufferedReader(new FileReader(fr));
                         String text = in.readLine();
                         if(text != null){
                         get_count = Integer.parseInt(text);
                         in.close();
                         else{
                              get_count = 0;
     else{                    
out = new BufferedWriter(new FileWriter(filepath));
     out.write("0");
            out.close();
               }          //Reading of the row count file ended.
          catch(Exception e) {
               e.printStackTrace();
          finally {
               try{               if (in != null) {
                         in.close();
          if (out != null) {
                         out.close();
          catch(Exception e) {
                    e.printStackTrace();
          return get_count;
     }

You are calling the readline() only once which means you are reading only the first line from the file...
Use a loop (Do-While preferably)
do{
//your code
}while(text == "")

Similar Messages

  • I wanted to know how to check my laptop's (hp pavillion g-6) on internet??

    i wanted to know how to check my laptop's (hp pavillion g-6) on internet??

    Hi,
    There are dozens things you can check, which one do you want to check ?
    Regards.
    BH
    **Click the KUDOS thumb up on the left to say 'Thanks'**
    Make it easier for other people to find solutions by marking a Reply 'Accept as Solution' if it solves your problem.

  • I want to know how to check my balance on an itune card that has been activated?

    Hi I purchased an itunes card and just wanted to know how to check the remaining balance on the card. Somewhat new to this.

    Redeem it.
    Once the card is redeemed, the balance is on your account, not the card.

  • I want to know how to create a new script that can be run in batch proces in Photoshop Element 11 ?

    I want to know how to create a new script that can be run in batch proces in Photoshop Element 11 ?

    Have a look at the menu file/process multiple files. You can choose to add your signature (or the caption) to the image and export the new files.
    If that solution is not flexible enough, consider using the very affordable (12$)  Elements+ add-on which offers a 'meta stamp' script :
    http://elementsplus.net/v5/en/meta-stamp.htm
    Otherwise, have a look at other free and good solutions like Faststone Photoresizer, Xnview...

  • Hi, i want to know how to check my iphone is original unlocked or locked?

    Hi, i want to know how to check my iphone is original unlocked or locked?

    A G5 iMac don't have video-in capability, so you can't just use a simple cable to connect the two Macs.
    Have a look/try at ScreenRecycler http://www.screenrecycler.com/ScreenRecycler.html
    Stefan

  • How to insert new line in a text file

    hi all,
    i wnat to know how can i insert a new line in a text file using java.
    for example i want the formate of the text like this
    1 2 3
    4 5 6
    until now i know only how to insert data but not new line.
    Thanks in advandce

    Hi you can put a new line in a text file using System.getProperty("line.separator"). This implementation will work for every OS.
    import java.io.*;
    class Demo{
    public static void main(String args[]) throws Exception {
    FileWriter fr = new FileWriter("FileDemo.txt");
         fr.write("AAAAAAAAAA");
    fr.write(System.getProperty("line.separator"));
    fr.write("AAAAAAAAAAA");
    fr.close();
    }

  • Removing New Line Character in Input file

    Hi Experts,
    I Have a question about "New Line Character". I searched in SDN before posting this thread, But I didn't get answer.
    Question:
    Let me say my Client requirement first. After loading the data(Millions of Records) into SAP through LSMW, they asked write a program for validation of those loaded records based on I/P file. I wrote a program and It is success full.
    But, the problem is when file is in Application server in 'BIN' format, a new line character(#) is created. While comparing the last record of each line, it doesn't match. How to remove this new line character(#) in I/P file for each line of record? Please see the below records for example
    PROVINCIA DE BUENOS AIRE|   |1870|AR| #
    PROVINCIA DE BUENOS AIRE|   |1876|AR| #
    BOX 7407 PRINCETON|   |085437407|US|NJ#
    5756 2 A   CAPITAL FEDERAL|   |1431|AR|00#
    Note: This New line character is not matching the string "#".
    Please help me guys, so many objects are related with this concept. I appreciate quick response. Please.
    Thanks
    Sai

    Hi Arun, Ravi,
    I wrote the code like this, here 'fil_curre' is currency key.
    IF <l_wa_file_data>-fil_curre CS cl_abap_char_utilities=>newline.
              REPLACE ALL OCCURRENCES OF REGEX cl_abap_char_utilities=>newline
                                            IN <l_wa_file_data>-fil_curre WITH ''.
            ENDIF.
    While executing the code, the cursor here, simply jumps to next step.
    Any enhancements to this code or any new ideas?
    Thanks
    Sai

  • CLIENT_TEXT_IO : cannot insert new line into a text file

    Facts:
    Developer 10g
    AS 10g
    Web utility
    Problem:
    i am traying to
    Open a text file. using CLIENT_TEXT_IO.FOPEN
    insert a record in to a text file using CLIENT_TEXT_IO.PUTF
    insert a new line using chr(10) or CLIENT_TEXT_IO.NEW_LINE
    or CLIENT_TEXT_IO.put_line
    insert the next record
    Close the file.
    all work except insert a new line
    Why !!!
    it was Working fine in 6i, but now in 10g and Webutil is not working
    plz help

    Hi you can put a new line in a text file using System.getProperty("line.separator"). This implementation will work for every OS.
    import java.io.*;
    class Demo{
    public static void main(String args[]) throws Exception {
    FileWriter fr = new FileWriter("FileDemo.txt");
         fr.write("AAAAAAAAAA");
    fr.write(System.getProperty("line.separator"));
    fr.write("AAAAAAAAAAA");
    fr.close();
    }

  • How do i read complete line from a text file in j2me?????

    how do i read complete line from a text file in j2me????? I wanna read file line by line not char by char..Even i tried with readUTF of datainputstream to read word by word but i got UTFDataFormatException.. Please solve my problem.. Thanks in advance..

    That is not my problem . i already read it char by char.. i am getting complete line..But this process is taking to much time..So thats why i directly wanna read complete line or word to save time..

  • How to add an space for every line in a text file in 46.B?

    Hi Friends!!
    My problem is the following,
    I need to add spaces in all lines of a text file
    Ej.'ABC ' , I'm using GUI_DOWNLOAD to download the internal table, but the function truncates all spaces, as it is 46B doesn't have the option for allowing the spaces at the end of each line,
    Do you know what can I do?? is there any other function module I could use?? I also tried with WS_DOWNLOAD but it didn't help!
    Thanks so much in advance!!!
    Frinee

    This a short example:
    data: begin of mytable occurs 0,
            line(2),
            lspace type x value '20',
            lenter type x value '0D0A',
          end of mytable.
    mytable-line = '1'.
    condense mytable-line.
    append mytable.
    mytable-line = '2'.
    condense mytable-line.
    append mytable.
    mytable-line = '3'.
    condense mytable-line.
    append mytable.
    call function 'GUI_DOWNLOAD'
         EXPORTING
           BIN_FILESIZE = 50
            FILENAME = 'C:\mybinfile.txt'
            FILETYPE = 'BIN'
         TABLES
            DATA_TAB = mytable
         EXCEPTIONS
           others = 9.

  • ITunes doesn't know how to check for updates?

    So i know that there is a noew version of iTunes, 6.0.4, why when i check for updates in iTunes does it say that 6.0.3 is the current version? it did this also when 6.0.3 was released. i'm kinda confused here, shouldn't iTunes just check the website and if there is a newer version tell me?

    I'd start with the following document, with one modification. At step 12 after typing GEARAspiWDM press the Enter/Return key once prior to clicking OK. (Pressing Return adds a carriage return in the field and is important.)
    iTunes for Windows: "Registry settings" warning when opening iTunes

  • How to start a new line in a text field?

    I tried the following formula to break for  a new line but it is not working.
    stringvar notes;
    stringvar newline;
    newline := chr(100);
    replace (notes := {HNO_NOTE_TEXT.NOTE_TEXT}, "\r\n", newline);
    Any suggestions?

    How could I accomplish the following.?
    Current data in the column.
    PREOPERATIVE DIAGNOSES:   1.  Right shoulder rotator cuff tear.   2.  Right shoulder biceps tendon disease with superior labral tearing.      POSTOPERATIVE DIAGNOSES:   1.  Right shoulder rotator cuff tear.   2.  Right shoulder biceps tendon disease with superior labral tearing.      SURGEON:  Jane, Doe, MD      ASSISTANT:  Jane, Doe, PA-C and Bob, Doe MD, orthopedic resident.  The assistance of a physician's assistant was required for limb positioning and placement of anchors.      ANESTHETIC: Interscalene block plus general.      DRAINS:  None.      COUNTS: Sponge and needle count were correct.      MATERIAL FORWARDED TO THE LABORATORY:  None.      OPERATION PERFORMED:   1.  Right shoulder arthroscopic rotator cuff tear.   2.  Right shoulder open subpectoral biceps tenodesis.   3.  Right shoulder subacromial decompression with acromioplasty.   4.  Right shoulder extensive glenohumeral debridement.   
    I would like the following in MS Excel.  I would like to pull the header out into a separate column.
    Header
    NOTE_TEXT
    PREOPERATIVE DIAGNOSES: 
    1.  Right shoulder rotator cuff tear.  2.  Right shoulder biceps tendon disease with superior labral tearing. 
    POSTOPERATIVE DIAGNOSES:
    1.  Right shoulder rotator cuff tear.  2.  Right shoulder biceps tendon disease with superior labral tearing. 

  • How to insert a new line character inside CDATA tag in the source xml data file?

    values for form fields in the xml data file is contained inside CDATA tags which is an Unparsed Format.
    Eg: [CDATA[IBM-01 ~ DSHFSJDSJ ~ FGFGFJ, ~ VA 665665]] delimited by "~" char
    Actual o/p:-
    IBM-01 ~ DSHFSJDSJ ~ FGFGFJ, ~ VA 665665
    Expected o/p is like :-
    IBM-01
    DSHFSJDSJ
    FGFGFJ,
    VA 665665
    live cycle product does not interpret ~ as a newline character. Please suggest which character should be used instead inside CDATA section or if there is any other way to fix this?

    I do not have any problem while using IE's XML parser
    for XML+XSLT merging.That is because IE's parser does not implement XML correctly.
    But when I use JAXP's Transformer object, it does not
    preserve the new lines inside attribute values and
    converts those into white spaces.That is exactly what the XML specifications say should happen.
    >
    ----If you have text that contains newlines, you
    should put it in an element, not in
    ----an attribute.
    That would be my last solution. But I'd really hate
    to change my logic just 'coz JAXP is not capable of
    handling new lines inside attribute values. I may be
    wrong... but If IE can keep those then there has to
    be a way to do the same from server side merging....Sure. Write your own parser with the same bug in it. But you don't have any right to demand that other people supply you with parsers that work incorrectly.

  • How to write new line character to a file from textarea

    Hi ,
    I want to save the contents of textarea in a file.The textarea may contain new line characters,
    I am getting the contents from the textarea using getText() method but after writing the contents to the file
    it stores the entire text in a single line.But I want the text as it apperars in the textarea.
    Please provide me a good solution.
    -mani

    maybe this code samples are useful to your problem
    File datatext = new File(fileName);
    try {BufferedWriter writer =new BufferedWriter(new OutputStreamWriter(new FileOutputStream(datatext)));
    writer.write(.......);
    writer.newLine();
    writer.close();                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Inserting new line to a text file at position #

    Hi,.
    Is it possible to do this in java?
    1. Open a new text File (woutFile)
    2. woutFile.write(" line #1\r\n"); // write new line
    3. woutFile.write(" line #2\r\n"); // write new line
    4.woutFile.write(" line #3\r\n"); // write new line
    5. Go to line #2 position on a text file
    6. Insert NEW LINE between line #2 and Line #3
    7. move to the end-of-file
    8.Close the file
    Please help

    Is it possible to do this? please look at question
    inside comments.Your question has already been answered. Beyond that,
    if you have some code and you want to know if it will
    work, then run it and see.The answer was no. It's one of the fundamental properties of files that you cannot insert content in the middle, just at the end. To insert content you first have to make room for it. In this respect a file works like an array and not like a linked list.

Maybe you are looking for

  • HT4314 Game Center Problem

    There isn't a catagory for this, but... Game Center games don't show up for me. None of them, not my friend's or mine. (Yes, I have used these games multiple times before) Help? (I wasn't sure where to ask this ^^)

  • Installed Firefox 4. But, it simply does not start. Freezes after I presss 'Search'

    I have just finished downloading Version 4. Switched off the computer. Started again by clicking on the shortcut icon. Somewhat bland screen appear, just giving a bar for search. When a search is typed in and 'search' button clicked, there is no resp

  • Multiple selection in LOV

    Hi, How to implement multiple selection in LOV region-query result table and return multiple values from LOV region back to the main page? Any help in this regard is greatly appreciated.

  • Looking for the Holy Grail

    I'm wondering what you guys and girls are using as fast storage for uncompressed hd work. My company is looking for a solution that is reliable, but less expensive than an XRaid solution. It can be raid0, raid5, raid10, I don't care, I just want to k

  • Can't Edit from Code View?

    For some reason one of my components seems to have an empty "array" as it's called describing a *filter* that doesn't exist.  In other words: <s:filters>                 </s:filters> This is causing me to get on error when I try to compile.  I can ta