How to write on a new line ("\n") to a file

I dont know how to write on a new line ... this method writes everything in long line. I tried doing pS.println("\n") before the pS.println(buffer.toString());
Some one please direct me :)
public void WriteToFile() {
     try {
          byte[] record = new byte[100];
          ByteArrayInputStream iS = new ByteArrayInputStream(record);
         DataInputStream iDS = new DataInputStream(iS);
          StringBuffer buffer = new StringBuffer();
          OutputConnection connection = (OutputConnection)
                                      Connector.open("file:///CFCard/readme.txt");
          OutputStream oS = connection.openOutputStream();
          PrintStream pS = new PrintStream( oS );          
          try {
           for(int x=1; x<=rs.getNumRecords();x++) {
           rs.getRecord(x, record, 0);                                                                                               
              buffer.append(iDS.readUTF());                          
              buffer.append(iDS.readUTF());              
              buffer.append(iDS.readInt());              
              buffer.append(iDS.readInt());              
              buffer.append("\n");
              pS.println("\n");
              pS.println(buffer.toString());                                          
             iS.reset();                   
          oS.close();
          connection.close();
         iS.close();
         iDS.close();        
          catch(ConnectionNotFoundException err) {
               Alert alert = new Alert("Error", "Cannot access file.", null, null);
             alert.setTimeout(Alert.FOREVER);
             alert.setType(AlertType.ERROR);
             display.setCurrent(alert);     
          catch(IOException err) {
          Alert alert = new Alert("Error", err.toString(), null, null);
        alert.setTimeout(Alert.FOREVER);
        alert.setType(AlertType.ERROR);
        display.setCurrent(alert);     
          Alert alr = new Alert("Completed Sending to a File", "Data written successfully!",null,null);
          alr.setTimeout(Alert.FOREVER);
          alr.setType(AlertType.WARNING);
          display.setCurrent(alr);
          }catch(Exception err) {
}

Stinkin' crossposter
http://forum.java.sun.com/thread.jspa?threadID=613784

Similar Messages

  • How do i create a new line when writing to file

    I am trying to write a few stings to a file but i cant get them to print on seperate lines. They all end up together. I tried to include the \n in the string but that didnt work. Any suggestions? I thought that this part would be simple.

    http://forum.java.sun.com/thread.jsp?forum=54&thread=450725&tstart=0&trange=15

  • 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();
    }

  • How can i go to new line

    How can i go to new line when iam writing data to a file by using write to spraedsheet file.vi every time.i mean i would like to go to newline everytime.

    Take a look at the attached code. I am writing a 2-D array to the file using the default method so it looks like
    1 2 3
    4 5 6
    7 8 9
    in the file.
    I then use the Line Feed Constant as a delimiter, and you can see it then looks like
    1
    2
    3
    4
    5
    6
    7
    8
    9
    The line feed and carriage return constant is on the String Pallette.
    Attachments:
    WriteSpreadSheet.vi ‏19 KB

  • How can I add a new line item for production order?

    HI all,
    How can I add a new line item for production order through BAPI/FM? Thanks in advance.

    Hi Mil,
      Unfortunetly SAP is not in front of me.
    But if possible go to BAPI transaction , check for any production order's bapi for CHANGE purpose. Where you will be able to add your new line.
    Reward if useful!

  • How to provide space and new line to the text in AI Script

    how to provide space and new line to the text in AI Script

    ?? can you explain better, can you at least add another sentence?
    space
    var mySpace = " ";
    new line
    var newLine = "\n";

  • 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();
    }

  • Add new line in the Flat file based on the field value

    Hi,
    Following is my Flat File -
    Customer   X      Y
    1001          1       2
    1002          0       1
    Based on the X and Y value I need to add new lines in the Flat file. If X>0 then add a new line with repeating row and Y>0 add again a new line with repeating row. If X or Y=0 then no need to add any repeating new line. 
    So, here for the above example I need output as-
    Customer    X    Y
    1001          1      2
    1001         1       2
    1001         1       2
    1002          0       1
    1002          0        1
    Suggest how we can achieve this?
    Regards,
    Tridib Konwar 

    Hi Tridib,
        I tried your scenario and You will have to use the custom xslt to get the expected result.
        Please find bellow the xslt code which you can use in your map.
    <?xml version="1.0" encoding="utf-16" ?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:var="http://schemas.microsoft.com/BizTalk/2003/var" exclude-result-prefixes="msxsl var" version="1.0" xmlns:ns0="http://PracticeAtul.XYFlatFileSchema">
    <xsl:output omit-xml-declaration="yes" method="xml" version="1.0" />
    <xsl:template match="/">
    <xsl:apply-templates select="/ns0:XYComp" />
    </xsl:template>
    <xsl:template match="/ns0:XYComp">
    <ns0:XYComp>
    <XYComp_Child1>
    <XYComp_Child1_Child1>
    <xsl:value-of select="XYComp_Child1/XYComp_Child1_Child1/text()" />
    </XYComp_Child1_Child1>
    <XYComp_Child1_Child2>
    <xsl:value-of select="XYComp_Child1/XYComp_Child1_Child2/text()" />
    </XYComp_Child1_Child2>
    <XYComp_Child1_Child3>
    <xsl:value-of select="XYComp_Child1/XYComp_Child1_Child3/text()" />
    </XYComp_Child1_Child3>
    <xsl:value-of select="XYComp_Child1/text()" />
    </XYComp_Child1>
    <xsl:for-each select="XYComp_Child2">
    <XYComp_Child2>
    <XYComp_Child2_Child1>
    <xsl:value-of select="XYComp_Child2_Child1/text()" />
    </XYComp_Child2_Child1>
    <XYComp_Child2_Child2>
    <xsl:value-of select="XYComp_Child2_Child2/text()" />
    </XYComp_Child2_Child2>
    <XYComp_Child2_Child3>
    <xsl:value-of select="XYComp_Child2_Child3/text()" />
    </XYComp_Child2_Child3>
    </XYComp_Child2>
    <xsl:if test="XYComp_Child2_Child2/text()!=0">
    <XYComp_Child2>
    <XYComp_Child2_Child1>
    <xsl:value-of select="XYComp_Child2_Child1/text()" />
    </XYComp_Child2_Child1>
    <XYComp_Child2_Child2>
    <xsl:value-of select="XYComp_Child2_Child2/text()" />
    </XYComp_Child2_Child2>
    <XYComp_Child2_Child3>
    <xsl:value-of select="XYComp_Child2_Child3/text()" />
    </XYComp_Child2_Child3>
    </XYComp_Child2>
    </xsl:if>
    <xsl:if test="XYComp_Child2_Child3/text()!=0">
    <XYComp_Child2>
    <XYComp_Child2_Child1>
    <xsl:value-of select="XYComp_Child2_Child1/text()" />
    </XYComp_Child2_Child1>
    <XYComp_Child2_Child2>
    <xsl:value-of select="XYComp_Child2_Child2/text()" />
    </XYComp_Child2_Child2>
    <XYComp_Child2_Child3>
    <xsl:value-of select="XYComp_Child2_Child3/text()" />
    </XYComp_Child2_Child3>
    </XYComp_Child2>
    </xsl:if>
    </xsl:for-each>
    </ns0:XYComp>
    </xsl:template>
    </xsl:stylesheet>
    If this answers your question please mark it accordingly. If this post is helpful, please vote as helpful.
    Atul Toke

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

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

  • Using dbms_lob append to insert text how do you insert a new line inbetween

    DBMS_LOB.APPEND (P_TEXT,'* Operator Phone,');
    ---- inbetween I need to insert new I am using DBMS_LOB.APPEND (P_TEXT,CHR(10)); IS there amy better method?
    DBMS_LOB.APPEND (P_TEXT,'* Operator Email Address,');

    Sorry if the question was not clear ---
    Lets say in the folowing example every write append needs to start on a new line followed by text. How do we do that?
    Do we add another writeappend(cvar,22, chr(10)); inbetween?
    dbms_lob.writeappend(cvar, 19, '<root><book><title>');
    dbms_lob.writeappend(cvar, length(r.title), r.title);
    dbms_lob.writeappend(cvar, 14, '</title><desc>');
    dbms_lob.writeappend(cvar, length(r.description), r.description);
    dbms_lob.writeappend(cvar, 27, '</desc></book><author_name>');
    dbms_lob.writeappend(cvar, length(r.author_name), r.author_name);
    dbms_lob.writeappend(cvar, 21, '</author_name></root>');
    Edited by: user521218 on May 7, 2009 12:34 PM

  • How do you get a new line in a description of an iCal event?

    I need to be able to create multiple lines in a description of an iCal event.  In the past, I used control return to get a new line.  In Mountain Lion, this does not show up as a new line, once the event has been saved.  It merges all of the text onto one line and creates new lines as the space dictates.  How can I force new lines in the event description between the words that I have chosen?

    I'm interested too.
    Please help, I had own method to management  iCal's event – new line, of 10.7 worked great – now is a little terrible for me :/

  • How do i create a new line item (say 20) in reference to line item 10

    Hi all,
    I am trying to map a scenario where i want to create a new line item with reference to an existing line item. Where do i get this option in SD, and how could i go about it?
    Thanks & Regards
    Ravi

    > In ECC6 if u go to VA01 and enter the SP and SH,
    > Press Propose Item Icon, then one window will pop-up
    > asking for Sale Document Number, enter the Number and
    > select- selection list, there  u will get all the
    > line item of the Sale Doc. Select and copy Material
    Hi i am on SAP 4.7. How could be the same handled here?

  • HOW TO WRITE STANDARD TEXT IN LINE LINE

    1)LINE
    2)LINE
    LIKE THIS

    hiii
    if you want to write same in standard text then you just need to press enter you will get second line & you can write there.it will come in next line only..in SO10 you will get the same screen for writing as you hav in SAP script.so new line is also there.or just press enter.& yaa if you want to use outline there then for particular variables or automated data you can use outline type.so number will be generated automaticaly.for this you will get help in help.sap.
    regards
    twinkal
    Edited by: twinkal patel on Jul 7, 2008 10:39 AM

  • How to search for a new line character in sql

    hi..i am using oracle 10g.
    basically i am looking for usage of columns.I want to see which all columns are used in
    joins.
    this is the quey i have written.
    but
    if there a new line between WHERE ,AND those scenarios are ignored.how to take care of these new line characters?
    SELECT DISTINCT s.TYPE, s.NAME, s.owner, table_name, column_name --,line,text
    FROM all_source s, cols c, all_dependencies d
    WHERE s.NAME = d.NAME
    AND d.referenced_name = c.table_name
    AND c.table_name = 'WSF_EDUCATION_ORGUNIT'
    AND column_name ='ORGUNIT_TYPECODE_OID'
    AND d.TYPE = s.TYPE
    AND d.TYPE <> 'PACKAGE'
    AND d.owner = s.owner ---FOR OVERLOADED OBJECTS
    AND ( (UPPER (text) LIKE
    '%' || 'AND' || '%' || column_name || ' ' || '=%'
    OR (UPPER (text) LIKE
    '%' || 'AND' || '%=' || ' ' || '%' || column_name
    || '%'
    UNION ---if there is where
    SELECT DISTINCT s.TYPE, s.NAME, s.owner, table_name,
    column_name ----,line,text
    FROM all_source s, cols c, all_dependencies d
    WHERE s.NAME = d.NAME
    AND d.referenced_name = c.table_name
    AND c.table_name = 'WSF_EDUCATION_ORGUNIT'
    AND column_name ='ORGUNIT_TYPECODE_OID'
    AND d.TYPE = s.TYPE
    AND d.TYPE <> 'PACKAGE'
    AND d.owner = s.owner ---FOR OVERLOADED OBJECTS
    AND ( (UPPER (text) LIKE
    '%' || 'WHERE' || '%' || column_name || ' ' || '=%'
    OR (UPPER (text) LIKE
    '%' || 'WHERE' || '%=' || ' ' || '%' || column_name
    || '%'
    )

    Hi,
    Not sure if I get it, but you can look for characters using the ascii and chr functions.
    You can change them using replace:
    A new line:
    SQL> select ascii('
      2  ') from dual;
    ASCII('')
            10(Just press enter between the quotes)
    Example how to replace it with a space:
    SQL> with t as ( -- generating test string:
      2  select 'this string has
      3  a new line' str from dual
      4  )
      5  --
      6  -- actual query:
      7  --
      8  select str
      9  ,      replace(str, chr(10), chr(32))
    10  from   t;
    STR                        REPLACE(STR,CHR(10),CHR(32
    this string has            this string has a new line
    a new lineIf that isn't clear of when I'm missing the point then please post some narrowes down examples of what you get now and your desired output. Remember to put the tag around any code example you're posting.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Maybe you are looking for

  • Quicktime fps

    I am relatively new to QT. I am having a problem with frame rate! I have some QT video's where I have set a frame rate of 60 fps but will only actually play at about 38/40 fps. What am I doing wrong. Model Name: Mac Pro Model Identifier: MacPro1,1 Pr

  • How do I get rid of box around selected finder items?

    How do I get rid of this black square box that has appeared on my finder items, and other things on my computer? Currently the black box is around the red x on top of the firefox window. It moves with the programs I have open. I would upload a screen

  • I am unable to upload whatsapp

    Device& software problem

  • The Data Access service is either not running or not yet initialized. Check the event log for more information

    Hi, I have SCSM with remote SQL and the SCSM Management server give below error Message: Failed to connect to server 'Name of Server' Microsoft.EnterpriseManagement.Common.ServiceNotRunningException: The Data Access service is either not running or n

  • URL stream breaks on reading

    Okay, I have a routine that works perfectly! Until a file is a certain size. I know it works on files that are 4k but not on 10k. What happens is it fetches the first part of the file and then just blocks (which it is supposed to until the file comes