Results 1 to 8 of 8
Thread: Read a file automatically
- 10-25-2011, 12:22 PM #1
Member
- Join Date
- Oct 2010
- Posts
- 25
- Rep Power
- 0
Read a file automatically
Hi,
I have a program where I need to open and read an excel file. I have finished developing this application but has a problem.
I need to open and read an xls file in this program. The same xls has to be read all the time when I run the application. but I have to distribute this application to many other people. So
I cannot give the file path as it varies with different users. like "C:\\sample.xls".
So how do I associate it with the .jar file so that it becomes a part of the program rather than being individual.
Any sort of help is appreciated.
Thanks
- 10-25-2011, 02:14 PM #2
Re: Read a file automatically
Can't you just pack it into the Jar?
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 10-25-2011, 02:58 PM #3
Member
- Join Date
- Oct 2010
- Posts
- 25
- Rep Power
- 0
Re: Read a file automatically
Did you mean zipping it along with the jar file and distributing?
I can do that. but even then, I need to demand that this file has to be unzipped to a particular location,
say if I have mentioned the path as "C:\\sample.xls" in the program, they need to unzip the file to that location "C:\\". Otherwise the file cannot be found and accessed.
I am wondering whether there are some way to import this file and make it a part of the jar file like adding an image to a form. I am still new to Java and working in netbeans. If so please let me know.
I am trying to avoid using a JFileChooser here as I have already couple of JFilechooser implemented in this applicaiton. and since this file which has to be selected remains the same everytime I run the program, I would like to select it by default.
Any sort of help is really appreciated.
Thanks in advance
- 10-25-2011, 04:12 PM #4
Re: Read a file automatically
No, that is not what I meant.
That is what I meant. I would try to work it out without using netbeans if you're still new to how things are set up.
Go through this tutorial: Lesson: Packaging Programs in JAR Files (The Java™ Tutorials > Deployment)How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 10-26-2011, 09:23 AM #5
Member
- Join Date
- Oct 2010
- Posts
- 25
- Rep Power
- 0
Re: Read a file automatically
Thanks for the idea. I could pack the xls file in the appropriate class folder.
But, could you please tell me, how could I represent its pathname in the program to access the file.
File ff=new File("what should be the path name here");
Thanks & Regards
- 10-26-2011, 10:05 AM #6
Member
- Join Date
- Oct 2010
- Posts
- 25
- Rep Power
- 0
Re: Read a file automatically
Thanks. I figured it out.
Using .getResourceAsStream
Regards
- 10-26-2011, 05:34 PM #7
Senior Member
- Join Date
- Aug 2011
- Posts
- 248
- Rep Power
- 2
Re: Read a file automatically
I know that you solved your problem but I have a question regarded to this topic:
I was just looking around the topic, and checked this link posted by KevinWorkman.Go through this tutorial: Lesson: Packaging Programs in JAR Files (The Java™ Tutorials > Deployment)
I started reading and it became interesting, so I keep on reading and I couldn't understand one thing:
There are alot of commands that I could not understand where to use them:
jar cf jar-file input-file(s)
jar tf jar-file
jar xf jar-file
and so on ..
This is definitely not Java, I tried using the cmd window and it won't work.
I'm missing somthing it's killing me!!
- 10-26-2011, 05:50 PM #8
Re: Read a file automatically
You should have posted this in your own thread.
But since we're here anyway, those are shell commands. You type them into the command prompt.
For more info: "Hello World!" for Microsoft Windows (The Java™ Tutorials > Getting Started > The "Hello World!" Application)How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
Similar Threads
-
Automatically upload file to FTP server
By dman in forum NetworkingReplies: 1Last Post: 03-21-2011, 03:48 PM -
update automatically an xml file
By freddy000 in forum New To JavaReplies: 2Last Post: 12-30-2010, 02:26 PM -
Automatically Generate an XML file
By svpriyan in forum XMLReplies: 2Last Post: 06-25-2009, 05:46 AM -
refreshing the page automatically if the configuration file changes
By anitha2324 in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 01-07-2009, 03:08 PM -
Automatically File Upload to server ...Help Needed
By 82rathi.angara in forum New To JavaReplies: 6Last Post: 08-05-2008, 07:13 AM


2Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks