aspose file tools*
The moose likes Java in General and the fly likes hwo do i read file from local systems D: drive ??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "hwo do i read file from local systems D: drive ???" Watch "hwo do i read file from local systems D: drive ???" New topic
Author

hwo do i read file from local systems D: drive ???

Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 757
how do i read a file from local system's hard drive

InputStream xml_file1 = ClassLoader.getSystemClassLoader().getResourceAsStream("D:\\xml\\mail.xml");

is this correct ???


Jigar Naik


Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Using the classloader requires a resource be in the classpath. Have a look at java.io.BufferedReader instead.

Your file is XML. You might also look at the javax.xml.parsers package too.
[ February 01, 2007: Message edited by: Paul Sturrock ]

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 757
what if i put mail.xml file in

jboss\server\default\xml_confi\mail.xml ???

will it work ?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Ah. Your code is running in an application server. In which case all you need do is put your resource in the classpath and read it in just as you were trying to do originally. However, you neeed to read the JavaDocs to see how you define where the resource is (an absolute path, like the one you have above, will not work).

That being said, what are you trying to do here? Are you trying to configure JBoss's mail service?
Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 757
I have created one method which send mail and one more method which read the e mail address of receiver from mail.xml file.

till now my mail.xml file used to go in .war file so there wasn't any problem of reading xml file but now xml file won't go with .war file.. it will stay out somewhere in jboss directory...
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

If the XML file is in you application's classpath, you should be able to read it fine. See here for a bit of an overview of JBoss's class loader architecture.
 
Don't get me started about those stupid light bulbs.
 
subject: hwo do i read file from local systems D: drive ???