Let's say I have below code:
String fileName = "name.txt";
FileOutputStream fileOut = new FileOutputStream(fileName);
wb.write(fileOut);
This way, the file will be created under bin folder of the project.
However, if I specific fileName at a whole path:
String fileName = "c:/temp/name.txt";
this file will be created at c:\temp folder.
Am Correct? And Why this happen, how FileOutputStream work?
It's not about how FileOutputStream
works, it's about the path that the operating system assigns to a process when it starts it
This path is called current working directory. From that directory all relative paths
are calculated. A simple file name is a relative path (to the current working directory).
If you specify an absolute path
then this path is used to create the file.
You can read more about paths on this wiki page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With