Results 1 to 6 of 6
  1. #1
    bikashg is offline Member
    Join Date
    Apr 2010
    Posts
    13
    Rep Power
    0

    Default Writing a block of text as it is to output file

    Hi Friends,

    I want to write a block of text as it is (I mean the text contains several newlines, semicolons, aphostrophe, tabs and so on) to console/file. I dont want to use \ to escape them because there are hell lot of many things to escape in the text.

    Can you please suggest me any inbuilt methods which will take just whatever is given and then dump into the console/file.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,620
    Rep Power
    25

    Default

    What format is the text currently in? How are you getting it into your program?
    Do you want to write the text as bytes to not have any editting done on the contents. For example the tab character has a hex value of 0x0F, newline is 0x0D. There shouldn't be any problems with ; & '

  3. #3
    bikashg is offline Member
    Join Date
    Apr 2010
    Posts
    13
    Rep Power
    0

    Default

    Hey Norm,

    The text is an XML text and just contains anything and everything. I get it into the program by reading an input_XML file.

    As far as I can transport the data "exactly" I dont care how it gets transfered..bytes or string!

    Since I get the data from input_XML in string (), I need some inbuilt methods that can take that string as it is and write to console/file.

    Any suggestions, please?

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,620
    Rep Power
    25

    Default

    If a String, have you tried System.out.print() to write it to a console file?

  5. #5
    bikashg is offline Member
    Join Date
    Apr 2010
    Posts
    13
    Rep Power
    0

    Default

    May be I was a bit unclear:

    I want to write something like:

    System.write.print("
    <ROOT>
    <FIRST ELEMENT>1st & Top text</FIRST ELEMENT>
    <SECOND ELEMENT attribute= "http://www.w3.org/1999/02/22-rdf-syntax-ns#> </SECOND ELEMENT>
    .....
    ......
    and so on
    ");


    but print method wont allow this. I will have to use a lot of \

    Can you please suggest me any method that can print such text without me putting a \

  6. #6
    curmudgeon is offline Senior Member
    Join Date
    May 2010
    Posts
    436
    Rep Power
    5

    Default

    I generally try to avoid hard-coding strings like that into my program and usually find it much easier to put that in a text file, and then read the text into my program. If I do this, I can either read in the whole thing, or else read it in line by line, placing each line into an ArrayList of String (ArrayList<String>). If read from a file, you don't have to worry about escaping characters etc.

    YMMV

    What I find missing here is the context within the bigger picture. What is this small bit of code trying to do with regards to your complete program? Often you don't really want a solution to your code question but rather a whole different and more logical approach to the underlying problem.

    Suerte.
    Last edited by curmudgeon; 05-30-2010 at 12:40 AM.

Similar Threads

  1. Replies: 1
    Last Post: 02-27-2010, 02:29 AM
  2. writing to text file problem
    By blumdiggity in forum Networking
    Replies: 1
    Last Post: 02-26-2010, 03:43 PM
  3. Help in writing the output in html file
    By aks.nitw in forum Advanced Java
    Replies: 5
    Last Post: 01-18-2010, 02:33 PM
  4. How to break a text file into block.
    By kinnylaw in forum New To Java
    Replies: 1
    Last Post: 11-28-2009, 09:49 AM
  5. writing text to file
    By notwist in forum New To Java
    Replies: 3
    Last Post: 04-25-2008, 05:20 AM

Posting Permissions

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