Writing new lines or carrige returns to a file

I am try to use either FileOutputStream or FileWriter to write a String to a text file. Only any \n or \r characters within the string open as square blocks in notepad when the string is writen, and all the text is on one line.
example code:
FileWriter writer = new FileWriter(name + ".txt", false);
String writeString = "Name: " + name + "\nSurname: " + surname;
writer.write(writeString, 0, writeString.length());
I am using Win98.

Try using a BufferedWriter... it has a method named newLine() that writes a new line.. below is the api:
public void newLine()
throws IOException
Write a line separator. The line separator string is defined by the system property line.separator, and is not necessarily a single newline ('\n') character.
Throws:
IOException - If an I/O error occurs

Similar Messages

  • Writing new lines or carrige returns to a text file

    I am try to use either FileOutputStream or FileWriter to write a String to a text file. Only any \n or \r characters within
    the string open as square blocks in notepad when the string is writen, and all the text is on one line.
    example code:
    FileWriter writer = new FileWriter(name + ".txt", false);
    String writeString = "Name: " + name + "\nSurname: " + surname;
    writer.write(writeString, 0, writeString.length());
    I am using Win98.

    Notepad is a Windows-bigoted program and requires \r\n to denote the end of a line. (Or is it \n\r? Can't remember.) If you only give it \n (as in your example) it doesn't understand and displays those boxes. Other Windows text editors do a better job.
    If you wrap your FileWriter in a PrintWriter, then you can just use its "println" method, which will take care of line-ending characters for you (it understands which OS you are running under and writes whatever combination of \n and \r is appropriate). Like this:FileWriter writer = new FileWriter(name + ".txt", false);
    PrintWriter printer = new PrintWriter(writer);
    String writeString = "Name: " + name;
    writer.println(writeString);
    writeString = "Surname: " + surname;
    writer.println(writeString);

  • Removing new lines and carriage returns

    Hi,
    SO I am new to regular expressions in java and I want to remove all the new lines and carriage returns from some text, and change them into <p>
    I have tried,
    Pattern pat = Pattern.compile("\n");
    Matcher mat = pat.matcher(text);
    StringBuffer sb = new StringBuffer();
    boolean result = mat.find();
    while (result){
    mat.appendReplacement(sb,"<p>");
    result = mat.find();
    mat.appendTail(sb);
    text=sb.toString();
    But it seems to have no effect. Anyone know what I'm doing wrong?
    Cheers
    Sandra

    Hello, i've got the same problem. I want to replace "carriage return" and "new line" from an text file. and i use the replace all function for a String object. The problem is, if i call the replace function like this:
    row = row.replaceAll ("\\r", "<p>");
    The "carriage return" is replaced, but not with the "<p>" characters, only with nothing.
    Lines from my original textfile:
    This is an example.
    I want to replace.
    After replacing with the function call row = row.replaceAll ("\\r", "<p>");
    This is an example.I want to replace.
    What is wrong. If i insert tab spaces and replace them, everything is fine. it is abug in my Java Version?
    I use j2re1.4.2_05
    I hope, anybody can help me

  • HT5449 Cannot Dictate "New Line" for a return key stroke.

    When using dictation I can't get "New Line" to work. It simply types this phrase! The "New Paragraph" command works, but adds all these additional spaces into my text. Has anybody got ideas on how to resolve? Is there another way to dictate a "return key"?

    I understand.
    Perhaps Apple Support in Australia would be willing to answer that one for you.  Their phone number is:
    (61) 1-300-321-456
    Or I wonder if there is some term used in Australia that means "new line" that might work (such as "return").  "Return" does not generate a new line here.

  • Writing new line character in DOM

    Hi,
    How to write a new line character after any node in DOM.
    for e.g.
    if the DOM structure is
    <ROOT>
    <FIRSTNAME>Mahesh</FIRSTNAME><LASTNAME>Kumar</LASTNAME>
    </ROOT>
    How to change it to this below form
    <ROOT>
    <FIRSTNAME>Mahesh</FIRSTNAME>
    <LASTNAME>Kumar</LASTNAME>
    </ROOT>
    Thanks,
    Sahil

    All you have to do is to add a Text node as a child of <root> before the <LASTNAME> element.. There is an 'insertBefore" method that can be used.
    The Text node has only a newline as its content. (Use "setNodeValue" to set the value.)
    Dave Patterson

  • How to add a new line at the end of eTEXT file

    Hi,
    I have modified the RTF template for the R12.1.3 Positive Pay File report (IBYPOS_PAY_en.rtf). Everything is good, except that the bank requires a "T" (Capital T) character in a new line at the end of the text file. Has any of you came across this before? How do I modify the template to achieve this?
    Thank you,
    Sinan Topuz

    I believe this is related to BI Publisher. Any comments would be greatly appreciated.
    Thanks,
    Sinan

  • New line for each segment for Inhouse files using bic mapping..!!

    Hi ,
    Idoc to File scenario.
    In the receiver adapter, we need to convert the XML into file(Inhouse format) by using seeburger mapping.
    We have generated the map for this in bic and used in Module configuration of receiver adapter.
    Now the question is I need to get each segment of XML file into a separate line in the output file like below.
    HDR ... ......
    DTL .........
    DTL ........
    where HDR is the header and DTL is the details segments.
    Iam getting the output in a single line like HDR.........DTL.........DTL.........
    but not as expected like above  .
    I tried by using newLine = true in module configuration, but no use.
    I digged into bic designer to search for any option , but no use.
    Kindly suggest me if any one has any idea on this.
    Thanks&Regards'
    Deepthi.

    Hi Deepthi,
        Did you find the solution, please let me now if you get.
    did you mention the below code to solve the issue.
    copy the below section in the NewMapping Program:
       SetDestinationDelimiter("SubElement", ">");
       SetDestinationDelimiter("Element", "~");
       SetDestinationDelimiter("Segment", "\n");
    Regards,
    Varun Reddy.K

  • XSLT - New Line/Carriage Return not displaying when deployed

    Hello everyone,
    I have an XSL Style Sheet that is supposed to transform an XML into plain text using Oracle SOA 11g BPEL transformation. The plain text transformation is working fine, but whenever I try to add a new line or carriage return, the text output doesn't reflect that. I've tried several ways of adding the line break but none of them have worked. This is the XSLT I'm using for testing purposes:
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:a="urn:oracle:b2b:X12/V4010/850" version="1.0">
    <xsl:output method="text" omit-xml-declaration="yes" indent="no"/>
    <xsl:template match="/a:Transaction-850">
    <!-- New line -->
    <xsl:variable name='newline'><xsl:text>
    </xsl:text></xsl:variable>
    <xsl:value-of select="a:Internal-Properties/a:Data-Structure/a:Property[@Name='InterchangeUsageIndicator']" />
    <xsl:text>&#xd;</xsl:text>
    <xsl:value-of select="$newline" />
    <xsl:text>&#xA;</xsl:text>
    <xsl:text>&#13;</xsl:text>
    <xsl:text>&#10;</xsl:text>
    <xsl:text>2000ITITM</xsl:text>
    </xsl:template>
    </xsl:stylesheet>
    When I try it out in an online XSLT test tool, it gives the output as expected:
    P
    2000ITITM
    When I deploy the composite, I noticed that the XSLT in the MDS repository ignores the line breaks, *#xAs, etc. and just closes the <xsl:text/> tags:
    <?xml version='1.0' encoding='UTF-8'?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:a="urn:oracle:b2b:X12/V4010/850" version="1.0">
    <xsl:output method="text" omit-xml-declaration="yes" indent="no"/>
    <xsl:template match="/a:Transaction-850">
    <xsl:variable name="newline">
    <xsl:text/>
    </xsl:variable>
    <xsl:value-of select="a:Internal-Properties/a:Data-Structure/a:Property[@Name='InterchangeUsageIndicator']"/>
    <xsl:text/>
    <xsl:value-of select="$newline"/>
    <xsl:text/>
    <xsl:text/>
    <xsl:text>2000ITITM</xsl:text>
    </xsl:template>
    </xsl:stylesheet>
    And so, because of that, it just gives me the following output:
    P2000ITITM
    I have no idea why it's ignoring the new line characters, so any guidance would be appreciated.
    Thank you all for your help and time!
    Edit: I tried concatenating as follows:
    <xsl:value-of select="concat('36','&#xA;')"/>
    <xsl:value-of select="concat('24','&#xD;')"/>
    ...which shows up as is when I look at it in the MDS repository, however the text output still shows no line breaks...
    Message was edited by: dany36

    Ah I'm such a newbie. I was able to get it displayed by doing the following:
    <xsl:variable name="newline" select="'&#xD;&#xA;'" />
    This would show up correctly in the MDS repository, too.

  • Problem in creating New line in --File writing(Urgent)

    Hi all
    I am facing a tipical problem.
    I am writing a Text file using FileWriter and i am using "\n" for writing a new line,
    but when i open notepad all are falling on a single line with a special char
    (if i open the text file in some other editor vie wis very fine)
    C-0-1@C-1-0@ C-2-1
    @ is where i am writing new line.
    but this king of writing is not supported by my third party tool to which i am sending the text file
    as parameter..
    Kindly any one provide me a solution.
    Bye

    newlines differ between windows and linux/unix. Windows' new line character is somthing like "\n\m" where linux uses "/n". So to keep your program platform independent I would suggest using System.getProperty("line.separator") so your code might look like:
    String s = "C-0-1" + System.getProperty("line.separator") + "C-1-0" + System.getProperty("line.separator") + "C-2-1";
    //then write the string to the filethis will give you the appropriate newline character for the platform your program runs on.

  • NEW LINE CHARACTER

    i am trying to load text into the BASIC TEXT of the material. The input file has matnr and the text. The file we loaded is fine. But in the text editor the # for new line character appears and this is causing problem while writing the text in a sapscript.
    so i am trying to remove the # for the new line character while we load the file. i am using
    data: c_tab like CL_ABAP_CHAR_UTILITIES=>CR_LF. to split the file and it is not being recognized. The input file is a tab delimited text file from excel. and it has " at the begining and ending.
    thanks in advance

    that is problem with Xls , If u have text with any Delimitors then u will get this kind of Stuff.
    prabhu,peram then i will get in text file as "prabhu,peram".
    Regards
    Prabhu

  • Inserting new line item in Sales order

    Hi,
    We are doing a feasibility check to find out whether a new line item can be successfully inserted into a sales order based on certain pricing conditions that is received through an ORDERS05 inbound idoc.
    I tried adding a new segment E1EDP01 to the existing idoc in the user exit EXIT_SAPLVEDA_011 assuming that the VA01 posting program would accept the new line item but that approach is not working.
    Looking at various posts in the forum, I gather that the best way is to use the function 'BAPI_SALESORDER_CHANGE'. Can anyone please let me know how exactly a new item can be inserted using this function module?
    Any help would be appreciated.
    Thanks

    Hi Sneha,
    Please use the FM 'BAPI_SALESORDER_CHANGE' to add a new line item as under:
    CALL 'BAPI_SALESORDER_CHANGE'
        EXPORTING
          salesdocument               = "Pass the Sales order no here"
          order_header_inx            =  "Pass the value of update flag as I as u need to "
                                                   "insert a new line item"
        TABLES
          return                             =  "Will contain the error/success messages"
                                                   "after the processing"
          ORDER_ITEM_IN            =  "Here pass the item info tht needs to be added"
    Also do a Commit Work after this FM call to reflect the changes in database.
    Regards,
    Chetan.
    PS: Reward points if this is helpful.
    Message was edited by:
            Chetan H. Dubey

  • File Adapter Write Operation inserts a new line at the end

    Hi,
    I am using the write operation in the File Adapter from BPEL Process. The data is written successfully to the file and file is also created in the location specified in the adapter wsdl. But in the file created, it creates a new line at the end of the file. This new line has to be avoided when writing data to a file.
    Has anyone faced this and solved this ?
    I am SOA 10.1.3.4.
    Cheers,
    - AR

    It is a bug in 10g and will be resolved in one of the versions of 11g.
    Cheers,
    -AR

  • File Adapter inserting New Line

    All -
    I'm stuck on this one.  Would anyone know why the File adapter would insert a New Line at the beginning of my file?  The file is output correctly with the exception of a blank line at the very beginning of the file.
    Are there any conversion parameters I need to supply for the receiver file adapter?  I currently have:
    data.endSeparator = 'nl'
    data.fieldFixedLenths = 30,30,15,3
    data.fieldNames = F1,F2,F3,F4
    data.fixedLengthTooShortHandling = Cut
    Thanks,
    Dave

    Ok, found the issue!
    The File Adapter is configured as FTP and when the file is FTP'd to the target directory and viewed using Internet Explorer, a carriage return/line feed is added to the beginnig of the file.  When I FTP the file from the remote directory to my local directory and then view the file, it's fine.  Not sure why Internet Explorer changes the formatting of the file.
    Bottom line - the remote file is fine.
    Cheers,
    Dave

  • Detecting new line characters

    How do I detect new line and carriage return characters with
    string functions like replace? It works if I actually insert a new
    line in the function by pressing return, but that messes up the
    formatting and makes reading the code less intuitive.

    You may need to look for both chr(10) and chr(13) depending
    on O/S. On *NIX you're likely to need to check for both.

  • Content conversion receiver channel new line at end of file

    hi,
    when i create a file using content conversion i get new line at the end of the file.
    can someone tell me please how to avoid this?
    ( i don't use any end separators. i only use addheaderline = 0 and fieldfixedlength).
    Thanks
    Tomer

    Hi Tomer,
    I guess wrong thread.
    Edited by: sudhir tiwari on Sep 11, 2008 2:43 PM

Maybe you are looking for

  • Backing up selected folders along with their metadata

    My Podcast folder in the itunes Music folder has grown up to 15 GB and I need to free up some space. Is there a way I can just move out a portion of this folder (or any folder for that matter) along with its metadata. and then easily have it back in

  • How do I change the genre of my book

    Hi My book was just listed in the iBookstore and it's listed in the wrong genre altogether. Is there a way to change this? Thank you!

  • Aperture 2.0.1-images flash by uncontrollably

    I just updated to 2.0.1 and now when I go to an album or project, the images flash by uncontrollably. It only stops when the last image in the project/album is reached. In other words, I cannot select an image at all. I have tried rebooting the compu

  • Email a d2k report

    Hi folks, i would like to know how can one email a report developed in d2k in the format shown in the report previewer to another user. null

  • Lock icon at top of screen

    At the top of Leopard is a small lock icon that just appeared. It seems to have something to do with keychain? How do I get it to not show.