1

I'm trying to access a created folder by FileInputStream, but Tomcat returned an exception.

java.io.FileNotFoundException:(directoy path) access denied.

Here's the code which creates the folder.

String dirname = "Myfolder";
File dir = new File( dirname );
dir.mkdirs();

My problem is that I cannot access this folder by InputStream.

チーズパン
  • 2,752
  • 8
  • 42
  • 63
toto totto
  • 65
  • 2
  • 10

3 Answers3

5

You can't access a directory with FileInputStream. You can read a file in the directory, or you can list the contents of the directory with e.g. new File(directory).listFiles().

user207421
  • 305,947
  • 44
  • 307
  • 483
0

Print out absolute path of this directory and make sure you are in the right place.

log.debug(">>> " + dir.getAbsolutePath());

And then check if user running JVM has access to that directory or even if it exists.

ilvez
  • 1,235
  • 3
  • 16
  • 27
  • Hi,is there anyone knows how to create a folder in the server memory, and i want to this folder be managed by the JVM. i dont want to store the folder in the system. here's what ive used to create a folder in the system: String dirname = "Myfolder"; File dir = new File( dirname ); dir.mkdirs(); but i dont want this i want to create the folder in the server memory. – toto totto Dec 15 '15 at 11:33
  • Maybe https://github.com/marschall/memoryfilesystem can help you? – ilvez Dec 15 '15 at 11:43
0

You can't open a directory with FileInputStream. To copy a directory, you can use the Files.copy(Path, Path, CopyOption...) method from JDK7:

String dirname = "Myfolder";
File dir = new File(dirname);
dir.mkdirs();
// ...
Files.copy(dir.toPath(), Paths.get("/target"), StandardCopyOption.REPLACE_EXISTING);

See this page from the Java Tutorial for more information: http://docs.oracle.com/javase/tutorial/essential/io/copy.html

Raphaël
  • 3,646
  • 27
  • 28