Results 1 to 4 of 4

Thread: of carriage returns & linefeeds !

  1. #1

    Thread Starter
    Lively Member moonguy's Avatar
    Join Date
    Apr 2001
    Location
    pune(india)
    Posts
    67

    of carriage returns & linefeeds !


    hi folks,
    i am usin filewriter to write text from a textfield to a file. after i save the file & open it in another editor, the cr&lf character appear as an unknown character in the file. can't file writer handle the cr & linefeed properly & what do i do to avoid this.
    thanks for any views .
    Last edited by moonguy; May 15th, 2001 at 10:20 AM.
    Vishal Mungi
    [email protected]
    www.geocities.com/vishalmungi

    VB,ASP,C++,Java,Oracle,MAX,photoshop,XML..,


    ~~~~
    \ - - /

  2. #2
    VirtuallyVB
    Guest

    Thumbs up

    import java.io.*;
    public class Cr{
    public static void main(String[] args){
    try{
    PrintWriter pw = new PrintWriter(new FileWriter("temp"));
    pw.println("Hello");
    pw.println("Bye");
    pw.close();
    }catch(IOException ioe){
    System.out.println(ioe);
    }
    }
    }

    Then check out file "temp". No funny characters.

    You also may benefit from Buffering:
    PrintWriter out
    = new PrintWriter(new BufferedWriter(new FileWriter("foo.out")));

    http://java.sun.com/docs/books/tutor.../io/index.html

  3. #3

    Thread Starter
    Lively Member moonguy's Avatar
    Join Date
    Apr 2001
    Location
    pune(india)
    Posts
    67

    Question

    see i m doin it like this :-

    out=new FileWriter(file);
    out.write(ta.getText());

    so how can i send each line of the text box seperately? the question is that can't the filewriter handle the carriage returns occurring in the textfield's text?
    Vishal Mungi
    [email protected]
    www.geocities.com/vishalmungi

    VB,ASP,C++,Java,Oracle,MAX,photoshop,XML..,


    ~~~~
    \ - - /

  4. #4

    Thread Starter
    Lively Member moonguy's Avatar
    Join Date
    Apr 2001
    Location
    pune(india)
    Posts
    67

    too heavy?

    this does it but is'nt this too heavy on the resources(4 new objects)

    Code:
    StringReader sr = new StringReader(ta.getText());	    BufferedReader br = new BufferedReader(sr);
    FileWriter fw = new FileWriter("fubar.txt");	   
    PrintWriter pw = new PrintWriter(fw);	    		
    String s = br.readLine();
     while(s != null)
    {
     pw.println(s);
     s = br.readLine();
    }	  	   
     br.close();	
     sr.close();
    please tell me if there is any other way
    Last edited by moonguy; May 17th, 2001 at 06:19 AM.
    Vishal Mungi
    [email protected]
    www.geocities.com/vishalmungi

    VB,ASP,C++,Java,Oracle,MAX,photoshop,XML..,


    ~~~~
    \ - - /

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width