Get file from project folder java

The Solution to Get file from project folder java is

Well, there are many different ways to get a file in Java, but that's the general gist.

Don't forget that you'll need to wrap that up inside a try {} catch (Exception e){} at the very least, because File is part of which means it must have try-catch block.

Not to step on Ericson's question, but if you are using actual packages, you'll have issues with locations of files, unless you explicitly use it's location. Relative pathing gets messed up with Packages.



In this example, using File f = new File("x.txt"); inside of will throw a file-not-found exception.

However, using File f = new File("src/x.txt"); will work.

Hope that helps!

~ Answered on 2013-06-25 01:06:53

Most Viewed Questions: