Results 1 to 8 of 8
Like Tree2Likes
  • 1 Post By lemontree45
  • 1 Post By KevinWorkman

Thread: Read a file automatically

  1. #1
    lemontree45 is offline Member
    Join Date
    Oct 2010
    Posts
    25
    Rep Power
    0

    Default 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

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,960
    Rep Power
    8

    Default 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!

  3. #3
    lemontree45 is offline Member
    Join Date
    Oct 2010
    Posts
    25
    Rep Power
    0

    Default 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

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,960
    Rep Power
    8

    Default Re: Read a file automatically

    Quote Originally Posted by lemontree45 View Post
    Did you mean zipping it along with the jar file and distributing?
    No, that is not what I meant.

    Quote Originally Posted by lemontree45 View Post
    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.
    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!

  5. #5
    lemontree45 is offline Member
    Join Date
    Oct 2010
    Posts
    25
    Rep Power
    0

    Default 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

  6. #6
    lemontree45 is offline Member
    Join Date
    Oct 2010
    Posts
    25
    Rep Power
    0

    Default Re: Read a file automatically

    Thanks. I figured it out.

    Using .getResourceAsStream

    Regards
    pbrockway2 likes this.

  7. #7
    tnrh1 is offline Senior Member
    Join Date
    Aug 2011
    Posts
    251
    Rep Power
    4

    Default Re: Read a file automatically

    I know that you solved your problem but I have a question regarded to this topic:
    Go through this tutorial: Lesson: Packaging Programs in JAR Files (The Java™ Tutorials > Deployment)
    I was just looking around the topic, and checked this link posted by KevinWorkman.
    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!!

  8. #8
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,960
    Rep Power
    8

    Default Re: Read a file automatically

    Quote Originally Posted by tnrh1 View Post
    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.
    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!!
    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)
    tnrh1 likes this.
    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

  1. Automatically upload file to FTP server
    By dman in forum Networking
    Replies: 1
    Last Post: 03-21-2011, 03:48 PM
  2. update automatically an xml file
    By freddy000 in forum New To Java
    Replies: 2
    Last Post: 12-30-2010, 02:26 PM
  3. Automatically Generate an XML file
    By svpriyan in forum XML
    Replies: 2
    Last Post: 06-25-2009, 05:46 AM
  4. refreshing the page automatically if the configuration file changes
    By anitha2324 in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 01-07-2009, 03:08 PM
  5. Automatically File Upload to server ...Help Needed
    By 82rathi.angara in forum New To Java
    Replies: 6
    Last Post: 08-05-2008, 07:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •