• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to include a text file in the Javaservlet?

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, All:
Hope someone can help me this problem? Any reply will be help for me.
regards
Eric
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What have you tried so far?
The simplest thing is to just open the file and read it into a byte array, then output the byte array.
 
Eric Wang
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi William Brogden:
First thanks for the reply, this is what i want to do in my java program.
I have few java program, they are using the same value for this three parameter.
1. this.driverName
2. this.conString
3. this.sql
this.driverName="oracle.jdbc.driver.OracleDriver";
this.conString="jdbc racle:thin:admin/user@backup..com.sg:1521 rcl";
this.sql="select * from Table1";
So I want to save this three parameter value in a text file, so every time I want to change it, I only need to change the text file, so all the java program will be change.
So how should I retrieve this parameter value from this text file? Or any other ways can slove this problem?
cheers
Eric
 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,
Keep these string values in a file say "c:\myinput.txt", and open this file using "FileReader" class. Pass this Reader objects to "BuffredReader".
e.g. code is...
BufferedReader bd= new BufferedReder(new FileReader("c:\myinput.txt"));
Now use "readLine" Method of BufferedReader to get the each line.
Still better way is to keep all your input in XML file and use XML parser to get the required tag values. If you have Tomcat as servlet runner, you have to set up all its parameters in XML file only.
Bye.
Regards,
Holla.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
make properties file instead of text file. this is very simple.
and then in your program retreive like this
Properties pr=new Properties();
String fname=new Properties("yourfile.properties");
FileInputStream in=new FileInputStream(fname);
prop.load(in);
String driver=prop.getProperty("this.driverName");
String con=prop.getProperty("this.conString");
and then u can make use of these strings anywhere like
DriverManager.getConnection(con);
hope this would help.
vikas
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A small correction to the code provided by vikas sahni. I think the extra "Properties" constructor was a typo, the code should probably look more like:

Note that for a properties file you should also remove the " quotes from your data values.
 
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Eric,
Go for .properties method. A sample MIS.properties file which I use is
regds
maha anna
 
Eric Wang
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, vikas sahni, Frank Carver, maha anna �CRaghavendra Holla :
Thank you very much for all your replies. I have been slove my problem. Thanks again. You are really a Java Expert. I hope this forum will keep going, and hope more people join in to this forum.
cheers
Eric
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic