Printing everything on same line

Hi all,
I want to write text on a text File in a formatted manner, such that there is line break after every line.The problem I am facing is that it print everything on same line. When we use "/n" it generates a dummy character. We are using FileWriter
String s="Hello"+"\n"+"Everybody";
FileWriter f=new FileWriter("abc.txt",true);
f.write(s);
f.close();
I want every time this code is runs it should print sentences on different line.

Then I would recommend that you wrap a PrintWriter around your FileWriter and use its methods named println(), then you won't have to worry about newlines yourself. Since a newline is different depending on what OS you run your program on, that is a safer approach than just typing "\n" (which only works as newlines on Unix type OS's btw, on Windows it comes out as garbage when viewd in for example Notepad since Windows uses "\r\n" for newline)
Like this (reusing your code)
FileWriter fw = new FileWriter("abc.txt",true);
PrintWriter pw = new PrintWriter(fw);
pw.println("Hello");
pw.println("Everybody");
pw.close();Another alternative is to use System.getProperty("line.separator") instead of "\n" to make it work on all platforms.
HTH,
Fredrik

Similar Messages

  • Is there a way to print over the same line of text?

    Hey everyone, does anyone know if it's possible to write over the same line in a console window? I am formatting a diskette an currently it is going:
    1 percent complete
    2 percent complete
    3 percent complete
    4 percent complete
    5 percent complete
    I am currently doing:
    System.out.println(bufferedReader.readLine());
    to display this .. is there anyway to write over and over on the same line?
    Thanks again.

    I just thought of something!!! Try this:
    System.out.println("When the zeros have printed twenty times the disk has been formatted\n");
    System.out.println("|-----------------------------------|"\n)
    Then add the zeros to the line underneath it as it formats.  This will give a progress bar effect.  The zeros, when completely done, should fill up the whole |---| segment.
    Hope this helps.
    Virum                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Sapscript : Printing Text In same line

    Hi Friends,
               I have created 2 standard text.
               I want to print the follwing in the same line -
               First standard text + <A hard coded value> + Second standard text.
    <b>           I have coded like this -</b>
               /:   INCLUDE SLP OBJECT TEXT ID ST LANGUAGE ZH
            =     : 999
            /:    INCLUDE YEARS OBJECT TEXT ID ST LANGUAGE ZH
               First two are coming in the same line but third one is coming in second line.
    Please suggest.
    Regards
    Kishor

    Hii
    '=:' works but try it by increasing your window size
    otherwise use READ_TEXT fm
    You pass it the Text Identification Details
    and it will retrieve the texts into the internal table (IT_TEXTS).
    Internal table to store standard texts
    DATA: IT_TEXTS like T_LINE occurs o with header line.
    CALL FUNCTION 'READ_TEXT'
         EXPORTING
            CLIENT                  = SY-MANDT
              id                      =       "Text ID
              language                =       "Laguage
              name                    =       "Text name
              object                  =       "text object
            ARCHIVE_HANDLE          = 0
       IMPORTING
            HEADER                  =
         tables
              lines                   = IT_TEXTS   "Internal table
       EXCEPTIONS
            ID                      = 1
            LANGUAGE                = 2
            NAME                    = 3
            NOT_FOUND               = 4
            OBJECT                  = 5
            REFERENCE_CHECK         = 6
            WRONG_ACCESS_TO_ARCHIVE = 7
            OTHERS                  = 8
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    The main inputs for the FM are Text name, Language, Text ID and Text object and can be located using the following procedure.
    <b>Step 1 Display the desired text with transaction (i.e. ME23)
    Step 2 Show long text for a particular text (i.e. Deliver To)
    Step 3 Select ‘Header’ from the Goto menu (Goto->Header). The following screen should appear displaying info needed to retrieve text using the ‘READ_TEXT’ function module (Text name, Language, Text ID, Text object)</b>
    Regards
    Naresh

  • SAPscript address name1 and name2 - print on the same line

    I want to print name1 and name2 on the same line in an address on a check. Does anyone know how to do that ? I am usign the ADDRESS SAPscript command.

    The ADDRESS command allows you to format according to different countries postal formats. If you want to put two lines in one, I don't think you can use the ADDRESS command, but will have to format it yourself.
    Rob

  • Column printing on the same line in reports

    guys,
    i have a report with lets say n no. of columns. Now i want to display column 1 and 2 on the same line, i.e without giving a line break (given the fact that my report is page wise and not tabular). Can i do that? If so, then how?
    Any help will be highly appreciated. Kindly reply asap

    Hi Mike,
          Sorry, I should have realized you were using LabVIEW's HTML VIs - and it doesn't look like they provide for Table "Nesting" (at least through 7.1)!
    Here's a couple of VIs that might help you out.  Util.HTML.Table builds the HTML for a table.  SideBySide.vi uses this Util to embed two tables into an HTML Report.
    I whipped these up just for you - so they may need "polishing".  Should you need to fine-tune the table-appearance, I'm afraid you're on your own, though there's lots of help on the web.  Don't worry, HTML is pretty easy - and you'll find a nice HTML resource here. 
    Cheers!
    Message Edited by tbd on 03-05-2007 12:47 AM
    "Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
    Attachments:
    Util.HTML.Table.vi ‏63 KB
    SideBySide.vi ‏68 KB

  • Printing Strings on same line questions

    I need to know how to print the same number of _ (underscores) as there are letters in a given string. I already have the int of the number of characters in the string but how do i use that to print the same number of underscores in ONE line, not vertically. responses are appreciated.

    In your loop that prints the underscores, use System.out.print("_"), rather than System.out.println("_"). Read the javadocs to see the difference between these two methods.

  • Printing on chars on the same line using system.out.println

    i have the following string:
    String msg = "This is a message brought to you by one and the only";
    msg.toCharArray(); //converted to a char array.
    i've written a loop which goes through each of the char elements
    and puts it in it's own array:
    int i = 0;             
    while (i < msg.length)
                    char[] test = {msg};
    System.out.println(test);
    the problem is system out println prints out each of the elements on seperate lines is
    it possible to have them in one line to reform the original string?

    No exactly sure what you are trying to do. Does this
    help?
    String msg = "This is a message brought to you by one
    and the only";
    char[] test = msg.toCharArray();
    System.out.println(test);
    not really because i want to convert the string to a char array and then reform it in another char array and then i can choose which elements i want included and not to be so that it can be printed on the same line. I can do it the following way:
    char[] test = {test[0], test[1]]};
    but say i want all the letters containing the chracter T (and again i can use the above solution and select the elements from the string but i don't want to hardcode it, say the string changes etc) in the test array so then i thought of writing a loop:
    while (test[i] == 'T')
    char[] test2 = {test[i]};
    System.out.println(test);
    i++;
    but it puts each T in a new line...

  • Standard text printed only on one line

    Hi experts,
    I have a standard text in several lines:
    Line 1
    Line 2
    Line 3
    but in the pdf form it's printing in the same line:
    Line 1 Line 2 Line 3...
    Any suggestions ?
    /Kiehn

    Hello!
    1) When you say you have Standard text is several line that does not mean, that system have is in several lines.
    I don't know if you are aware or not, but while SAP system always stores long texts in 70 (or about so) char segments the fact that they are printed on one or several lines is controlled solely by formatting column that precedes each line in TLINES table. So, does your text has line breaks or new paragraph marks before those lines?
    2) If everything in above is correct, than maybe you have to check the format you use to transfer text from SAP to Adobe (in interface/context). Please, recheck what is stated [here at SAP Library|http://help.sap.com/saphelp_nw70/helpdata/en/04/ecfab99fc345f8826490df387aaf82/frameset.htm]. All this together with correct format for field (Rich text or Plain text) plus (as stated by poster above) "Allow multiple lines" and "Expand to Fit" (vertically) formatting should do the trick.
    Regards,
    Petr Perstnev

  • Print data at new line in SAP Scripts

    Hi,
    Is there any way that i can print data at new line in sap scripts. I am looping my data and its printing in the same line but i need to print it at new line. Is there any formating options or any command to do that.
    Thanks

    Than you must take all the values from the internal table into the different variables and than print them.
    In program:
    READ TABLE ITAB INTO WA_TAB INDEX 1.
    IF SY-SUBRC = 0.
      VAR1 = WA_TAB-FIELD1.
    ENDIF.
    * read all the lines and fill the VAR variables
    In SAPScript:
    /E LINE_VAR
    /P &VAR1&
    /P &VAR2&
    /P &VAR3&
    /P &VAR4&
    Regards,
    Naimesh Patel

  • I need to print in only one line

    I don't know how i can print in the same line.
    I use the System.out.println() and the System.out.print(), but now i need print a line in the same position.
    thanks

    You mean you want to overwrite the existing line ? Presumably not leaving any of the text previously printed ?
    That's specific to the platform, and as such, Java doesn't directly support it. You want a curses library. Something like this will probably do:
    http://sourceforge.net/projects/javacurses/
    Alternatively, if you don't care if your code is portable and you know the details of the console in which the output will appear, you can insert control codes directly into your output. In point of fact, that will be adequate for quite a lot of platforms, since most common systems use a subset of the ANSI/VT100 control codes - which can be found here: http://www.fh-jena.de/~gmueller/Kurs_halle/esc_vt100.html
    Dave.

  • How to print a text of type text element and include text in same line

    hi,
    I am working on forms,
    i have to display like this in the form
    1.RFQ number, 2.Header text
    explanation for numbers
    1. The RFQ number is displayed using a variable so the text type is Text Element
    2. Header text, has to be got form the standard text , so the text type is include text.
    how can i print both in the same line.

    Hi ,
    You can use a charecter variable whos length >= length of RFQ no + Length of Header string .
    Concatenate both in this variable. And print the variable.
    Pls reward if useful.
    Laxman

  • How to print three different Barcodes in the same line

    I am trying to print Barcodes for three different fields in a single line, it is taking the combined one & printing only one barcode for  all those three fields.
       When I tested it by printing them in diff lines, it is working fine. But the requirement is to  print all fields in the same line

    Hi
    Look at this , may be useful
    To Create a Bar code prefix:
    1) Go to T-code - SPAD -> Full Administration -> Click on Device Type -> Double click the device for which you wish to create the print control -> Click on Print Control tab ->Click on change mode -> Click the plus sign to add a row or prefix say SBP99 (Prefix must start with SBP) -> save you changes , it will ask for request -> create request and save
    2) Now when you go to SE73 if you enter SBP00 for you device it will add the newly created Prefix
    Create a character format C1.Assign a barcode to the character format.Check the check box for the barcode.
    The place where you are using the field value use like this
    <C1> &itab-field& </C1>.
    You will get the field value in the form of barcode.
    Which barcode printer are you using ? Can you download this file and see.
    http://www.servopack.de/Files/HB/ZPLcommands.pdf.
    It will give an idea about barcode commands.
    Check this link:
    http://www.sap-img.com/abap/questions-about-bar-code-printing-in-sap.htm
    Check this link:
    http://help.sap.com/saphelp_nw04/helpdata/en/d9/4a94c851ea11d189570000e829fbbd/content.htm
    Hope this link ll be useful..
    http://help.sap.com/saphelp_nw04/helpdata/en/66/1b45c136639542a83663072a74a21c/content.htm
    go through these links and cose u r previous threads,
    http://www.sap-img.com/abap/questions-about-bar-code-printing-in-sap.htm
    smartform - barcode
    http://www.erpgenie.com/abap/smartforms.htm
    http://sap.ittoolbox.com/groups/technical-functional/sap-basis/print-barcode-with-smartform-634396
    http://sap.ittoolbox.com/groups/technical-functional/sap-dev/printing-barcode-733550
    Detailed information about SAP Barcodes
    A barcode solution consists of the following:
    - a barcode printer
    - a barcode reader
    - a mobile data collection application/program
    A barcode label is a special symbology to represent human readable information such as a material number or batch number
    in machine readable format.
    There are different symbologies for different applications and different industries. Luckily, you need not worry to much about that as the logistics supply chain has mostly standardized on 3 of 9 and 128 barcode symbologies - which all barcode readers support and which SAP support natively in it's printing protocols.
    You can print barcodes from SAP by modifying an existing output form.
    Behind every output form is a print program that collects all the data and then pass it to the form. The form contains the layout as well as the font, line and paragraph formats. These forms are designed using SAPScript (a very easy but frustratingly simplistic form format language) or SmartForms that is more of a graphical form design tool.
    Barcodes are nothing more than a font definition and is part of the style sheet associated with a particular SAPScript form. The most important aspect is to place a parameter in the line of the form that points to the data element that you want to represent as barcode on the form, i.e. material number. Next you need to set the font for that parameter value to one of the supported barcode symbologies.
    <b>Reward points for useful Answers</b>
    Regards
    Anji

  • Print different text elements on the same line

    Hi all,
    1.
    Is it possible to print different text elements on the same line ? with multiple write_form
    CALL FUNCTION 'WRITE_FORM'
         EXPORTING
             element       = 'TITLE1'
             WINDOW        = 'INFO'
         EXCEPTIONS
              ELEMENT       = 1.
    CALL FUNCTION 'WRITE_FORM'
         EXPORTING
             element       = 'TITLE2'
             function      = 'APPEND'
             WINDOW        = 'INFO'
         EXCEPTIONS
              ELEMENT       = 1.
    How to print TITLE1 and TITLE2 on the same line ?
    TITLE2 in bold.
    2. How to print 2 text elements on the same line with include statement ?
    /: include test1 ...
    /: include test2
    Thanks
    Edited by: Moo Yac on Sep 22, 2008 8:23 AM

    To be more specific :
    I want to print the following
    Text_symbol1:$Var1$      Text_symbol:$Var2$
    on the same line.
    where Text_symbol1 and Text Symbol2 are defined in SO10 for different languages.
    Thanks.

  • HELP please! :) My ipod gets like lock, everything appear with lines, I already restore like three times the ipod and still happens the same, what can I do? and on some app store they just told me that restore, but well I do and is the same!

    My ipod gets like lock, everything appear with lines, I already restore like three times the ipod and still happens the same, what can I do? and on some app store they just told me that restore, but well I do and is the same! What can I do?? and is new, I buy it on march!
    This is a image of the ipod already restore, and everytime looks like that!

    If restoring the iPod to factory defaults/new iPod dow not solve the problem you likely have a hardware problem.  In that case either make an appointment at the Genius Bar of an Apple store or call AppleCare.  If defective, Apple will replace your iPod at no cost.

  • FSG report not printing column values on same line but sequentially

    FSG report problem:
    We have defined 2 FSG reports 'Balance Sheet - Total' and 'Balance Sheet - Detail'. Both reports have 3 column values, namely the value in Euro (our Functional Currency), the value in MUR - Mauritian rupees (our reporting currency) and the rate of exchange.
    The report 'Balance Sheet - Total' displays these values for assets e.g.:-
    EURO MUR Rate of exchange
    Non-current assets
    1. Intangible assets ? ? ?
    2. Other investments ? ? ?
    (note: ? represents a certain value)
    The report 'Balance Sheet - Detail' displays values as follows :-
    Account EURO MUR Rate of exchange
    1. Property & Equipment
    A10101 Building Cost ? 0.00 0.0000
    A20105 Motor Veh Accum Dep ? 0.00 0.0000
    TOTAL ? 0.00 0.0000
    A10101 Building Cost 0.00 ? n/m
    A20105 Motor Veh Accum Dep 0.00 ? n/m
    (note: ? represents a certain value)
    What we don't understand s why the 'Balance Sheet - Detail' report repeats the display of column values in MUR FOLLOWING the display in EURO, instead of displaying column values for EURO and MUR on the same line, just like in the case for 'Balance Sheet - Total'.
    Is there anything in the definition of column set, row set or report set should I change?
    Can anybody help. Thanks.
    null

    The problem is related to defining the column set properly. It is OK with the first report and needs modification for the second. Formatting is also important so that they appear in the same line(row). The columns need to be linked to the fileds and assignment to set of books is also important as mentioned by Rajsekhar

Maybe you are looking for

  • Memory usage of excel stays high after Macro is executed and excel crashes after trying to close it

    Hi, I'm trying to resolve an issue with an excel based tool. The macros retrieve data from an Oracle database and do calculations with the data. They also open and write into files in the same directory. The macros all run and finish the calculations

  • How to Start/Stop from Server Manager

    Hello, I am trying to figure out how to start/stop/restart my coldfusion servers from server manager.  I have seen the instruction at this link: http://help.adobe.com/en_US/ColdFusion/9.0/Admin/WSfd7453be0f56bba4-2a6b48f122a6582c7f-7ff e.html However

  • Flex in Air

    If I create a file with Flex 3, then compile with Air will work?

  • Looking for a Java tutor/mentor.

    Greetings. I've recently had quite a hard time figuring out the programing projects for my university computer science course. Seeing as how the teaching assistants aren't very helpful, I am in search of somebody who would be able to help me/discuss

  • [CS4] How to create list entries having button using ADM ?

    Hi All, I  want to create list box using ADM whose entries can have button. like we see in layer panel, there is a button to select arts of layer as figure shows. I tried to use function like  sADMItem->AddItem(listBoxRef,linkButton)  but there is no