0

I am attempting to create a standalone app and the app uses a local csv file to pull data from. I was hoping to send this app to friends for a niche use but I have realized that should the csv not be included, there is no way of me finding out where they stored the data and the file path for it. I need the csv to be included in the jar file with the code still reading it.

I have tried a file reader loop and importing the file directly to the project but neither have succeeded so far. I am not looking to use OpenCSV unless it is the last option as I would have to rewrite about half the code.

1
  • 2
    Better to load your files/images as resources: Netbeans Eclipse (including csv files). You could have the best of both worlds: read a file provided by the user, else your own csv as resource in the jar Commented Nov 24, 2022 at 21:33

1 Answer 1

3

You can include the CSV (and any other file) into the jar. A jar file is just a zip archive - you can verify that by renaming it and opening it with any archive viewer.

Now at runtime the file is read-only, and you have to access it via the classpath, not via the filesystem. Here is an example how to access a text file - and any other file also needs to be opened as stream: How to read text file from classpath in Java?

These files that you add to the jar are called resources, and as @g00se already mentioned: Here is how to do it in

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.