COBOL
COBOL

Reputation: 1041

Spring - Loading a folder from project structure as a directory?

I have written an application using Spring. I have a package called "Services" that has a "Resources" folder. In that folder are a text file (file.txt) and a folder (write). I have managed to load the text file using the following lines of code:

 URL file = this.getClass().getResource("/file.txt");
 File myFile = new File(file.getFile())

However I am having opening the folder. The following does not seem to work:

 URL folder = this.getClass().getResource("/write");

Running the line about throws a NullPointerException. Can anyone suggest ways in which I can accomplish this task?

Upvotes: 0

Views: 149

Answers (1)

aglassman
aglassman

Reputation: 2653

I believe you need to end your string with "/". The following may work:

URL folder = this.getClass().getResource("/write/");

Upvotes: 1

Related Questions