0

If I import a .jar into a Java project(Eclipse) in which there is a function using an IO and a File with a given path/name to load that file, and I call that function within a class in my project, where does the file have to be? Would it have to be in the .jar? In the project folder? The same folder as the .jar?

Yaakov Schectman
  • 301
  • 1
  • 2
  • 10
  • Put files on places where u mention and check what will be output like error/work? – bNd Jan 20 '15 at 03:08
  • It depends on the path that java code inside the jar uses. If there is specific path and just the filename, then the file should be present on classpath – Juned Ahsan Jan 20 '15 at 03:12

1 Answers1

0

File represents a file in the filesystem.

If you don't use absolute paths, the path will be relative to the working directory of your application.

By default, the working directory of a Java application started as part of a Java project from Eclipse will be the root folder of that Java project. You can change it in the "Run" dialog options.

If you don't want to load from the filesystem, but from a resource contained within the Java project itself (so that it can be included in the jar file), you should not use File, but the classloader.

Community
  • 1
  • 1
Thilo
  • 257,207
  • 101
  • 511
  • 656