Results 1 to 6 of 6
- 05-29-2010, 10:50 PM #1
Member
- Join Date
- Apr 2010
- Posts
- 13
- Rep Power
- 0
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.
- 05-29-2010, 11:12 PM #2
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 ; & '
- 05-29-2010, 11:17 PM #3
Member
- Join Date
- Apr 2010
- Posts
- 13
- Rep Power
- 0
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?
- 05-29-2010, 11:28 PM #4
If a String, have you tried System.out.print() to write it to a console file?
- 05-29-2010, 11:34 PM #5
Member
- Join Date
- Apr 2010
- Posts
- 13
- Rep Power
- 0
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 \
- 05-29-2010, 11:38 PM #6
Senior Member
- Join Date
- May 2010
- Posts
- 436
- Rep Power
- 4
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-29-2010 at 11:40 PM.
Similar Threads
-
Im writing to a file and i want to skip lines while writing to a text file.
By Broden_McDonald in forum New To JavaReplies: 1Last Post: 02-27-2010, 01:29 AM -
writing to text file problem
By blumdiggity in forum NetworkingReplies: 1Last Post: 02-26-2010, 02:43 PM -
Help in writing the output in html file
By aks.nitw in forum Advanced JavaReplies: 5Last Post: 01-18-2010, 01:33 PM -
How to break a text file into block.
By kinnylaw in forum New To JavaReplies: 1Last Post: 11-28-2009, 08:49 AM -
writing text to file
By notwist in forum New To JavaReplies: 3Last Post: 04-25-2008, 04:20 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks