users@jax-rpc.java.net

Re: Opening reading text file from web service

From: Baltz, Kenneth <Kbaltz_at_FIRSTAM.COM>
Date: Tue, 17 Dec 2002 08:52:53 -0800

I have found the following works for me: place your configuration file
somewhere in the classpath of your application. .../WEB-INF/classes is fine.
Then, use Class.getResourceAsStream( "/file_location.data ) to retrieve the
file. The advantage is that your configuration file can be place in your
.war file and read from there. If you use FileInputStream, it has to be
available directly from the file system.

K.C.

> -----Original Message-----
> From: jagan Kommineni [mailto:jagan_at_CSSE.MONASH.EDU.AU]
> Sent: Monday, December 16, 2002 11:02 PM
> To: JAXRPC-INTEREST_at_JAVA.SUN.COM
> Subject: Opening reading text file from web service
>
>
> Hello Friends,
>
> I wrote a simple java service and deployed using jwsdp-1_0_01
> tools kit.
> My service need to read some configuration information for
> processing it.
>
> I kept the file in "/home/jagan/jwsdp-1_0_01/work/Standard\
> Engine/localhost/hello-jaxrpc/WEB-INF/classes"
> that where the application was deployed.
>
> ==========================================
> My scripts for service is as follows for service implementation
> ------------------------------------
>
>
> package hello;
>
> import java.util.Hashtable;
> import java.util.Dictionary;
> import java.util.Enumeration;
> import java.util.StringTokenizer;
> import java.io.*;
>
> public class HelloImpl implements HelloIF {
> public String sayHello(String s) {
> Hashtable file_location = new Hashtable();
> String line;
> StringBuffer buf = new StringBuffer();
> try {
> BufferedReader in = new BufferedReader(new InputStreamReader(
> new FileInputStream("file_location.data"),
> "JISAutoDetect"));
> while(true) {
> String str = in.readLine();
> if(str == null) { break; }
> StringTokenizer
> tokens = new StringTokenizer(str, " ");
> file_location.put(tokens.nextToken(),tokens.nextToken());
> }
> }
> catch(FileNotFoundException e)
> {
>
> }
> catch(UnsupportedEncodingException e1)
> {
>
> }
> catch(IOException e2)
> {
> }
>
> if(file_location.containsKey(s))
> {
> return file_location.get(s)+"";
> }
> else
> {
> return "No data found on server for " + s;
> }
> }
> }
> =================================================================
>
> In fact while packaging the files, I packaged the
> data file along with other class files. While
> deploying, the tool kept at this location.
> Where do I need to keep for my web service to read
> text file.
> Is there any body have any idea.
> with regards,
>
> Jagan
>
>
>
> ===========================================
>