DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2006
    Posts
    2

    Unhappy Writing to files and newlines

    Hi

    I'm trying to write a string to a text file for import into a database. I can grab the output text from the output window and paste it into a new document that then imports correctly, but when I write the string directly to a new text file the carriage returns turn into little boxes (can't post an example because pasting them here turns them into carriage returns)
    I'm sure I'm not getting something - tried both UTF8 and ISO char encodings. Latest attempt below:

    try {
    Writer out = new BufferedWriter(new OutputStreamWriter(
    new FileOutputStream("C:/spudtwo.txt"), "UTF8"));
    out.write(hand);
    out.close();
    } catch (UnsupportedEncodingException e) {
    } catch (IOException e) {

    Any help gratefully received.

  2. #2
    Join Date
    Aug 2003
    Posts
    313
    Try using the PrintStream class, works just like System.out:
    Code:
    String hand = "INSERT INTO people VALUES ('bob', 'bobby');"; // Note no newline
    PrintStream out = new PrintStream(new FileOutputStream("C:\\spudtwo.txt"));
    out.println(hand);
    out.close();
    Hope this helps.
    ~evlich

  3. #3
    Join Date
    Aug 2006
    Posts
    2
    That's great, thanks.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links