Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 18th, 2002, 07:42 AM
harrylmh harrylmh is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2001
Location: Australia
Posts: 69 harrylmh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 15 m 48 sec
Reputation Power: 7
Servlet reading a file...

Hello,

How do I get a servlet to read a file? I need to read a .txt file and store its contents in a String variable. However, no matter where I put the .txt file, the servlet never seems to find it.

Thanks

Reply With Quote
  #2  
Old September 18th, 2002, 08:29 PM
bricker42 bricker42 is offline
Moderator =(8^(|)
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2002
Location: Sacramento, CA
Posts: 1,710 bricker42 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 38 sec
Reputation Power: 8
Send a message via AIM to bricker42
Here's the class to use:
http://java.sun.com/j2se/1.3/docs/a...FileReader.html

I'd suggest wrapping it in a BufferedReader, like
Code:
BufferedReader in  = new BufferedReader(new FileReader("foo.in"));

then you can use the readLine method from BufferedReader.

Reply With Quote
  #3  
Old September 22nd, 2002, 11:41 PM
corykwalker corykwalker is offline
Database Expert
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Posts: 20 corykwalker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Servlets read files just as any other Java application does. You will need to import the java.io.* package.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Servlet reading a file...


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway