Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

how to get plain text in file using print stream

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hai,


i am facing problem with printstream.if i am giving html structure inside of printstream, I am getting as such what i am giving inside of printstream.

Example program:
FileOutputStream outfile=new FileOutputStream("d:\\temp\\Fn1.txt");
PrintStream p = new PrintStream( outfile);
p.println( "<h3>Test Output</h3>" );
p.println( "<table><tr><td>x1</td>" );
p.println( "<table><tr><td>x2</td>" );
p.println( "<table><tr><td>x2</td>" );

..but i want result in a file like;

Test Output
x1
x2
x3

please help me

Regards
Babu
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Perhaps you should be writing this to a html file instead of a txt file. You should then open the HTML file in a browser like Internet explorer or firefox.
I dont see how this would work with a txt file (unless you sub class the PrintStream implementation and parse the String to suit your needs).
 
Ranch Hand
Posts: 1325
Android Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by yoga babu:


..but i want result in a file like;

Test Output
x1
x2
x3



escape Sequences "\n" is used to Insert a newline.

did you try this in your print statment ?
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Saif uddin:


escape Sequences "\n" is used to Insert a newline.

did you try this in your print statment ?



He's using println, which automatically adds a newline character.


yoga,
If you want plain text why are you writing HTML to the file?
 
yoga babu
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hai,

Actually i want to print datas from database using resultset and assigning to variable.i want to print this datas in to the file using printstream in the table format..is it possible.

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:pro","pro","pro");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from Csgkut_slot5_6 where Module='7613_1_slot5'");

p.println("date Module Max High Curr Over");
while(rs.next())
{

String date=rs.getString(1);
String mod=rs.getString(2);
String max=rs.getString(3);
String high=rs.getString(4);
String curr=rs.getString(5);
String over=rs.getString(6);



p.println( " '"+date+"' '"+mod+"' '"+max+"' '"+high+"' '"+curr+"' '"+over+"');

}


i am getting the result but i want to introduce table format in the file ...

for that is it possible to introduce html coding in printstream to get table format in resulting file.


Regards
Babu
 
yoga babu
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hai,,


Any solution for this problem.In the text file the datas are not in correct order(irregular manner )

result will be like this,

aaa bbbb cccc
aaaaa bbbb ccccc
aaa bbbb cccc
aaaaaa bbbbb ccccc

i cant able to assign constant length for the string.

pls forward all your ideas.


Thank you
Babu
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want your columns to line up in a plain text file, you'll need to either write your own code that measures string length and inserts white space where needed or look for a third party formatter than can do this for you.

JDK1.5 and above has printf capability but depending on the container you're using, you may not be able to use 1.5 features from JSP scriptlets (even if you're using the 1.5 JRE. (This is yet another reason to factor non view related code out of your JSPs.)

Since writing to a file with Java is not really JSP specific (other than the scriptlet limitation listed above), I'm going to move this to Java In General (intermediate). Someone there may know of a formatter that can you could use for this.
[ December 01, 2006: Message edited by: Ben Souther ]
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic