I have a question regarding to the Java File class. When I create a File instance, for example,
File aFile = new File(path);
Where does the instance aFile store in the computer? Or it stores in JVM? I mean is there a temp file stored in the local disk?
If I have an InputStream instance, and write it to a file by using OutputSteam, for example
File aFile = new File("test.txt");
OutputStream anOutputStream = new FileOutputStream(aFile);
byte aBuffer[] = new byte[1024];
while( ( iLength = anInputStream.read( aBuffer ) ) > 0)
{
anOutputStream.write( aBuffer, 0, iLength);
}
Now where does the file test.txt store?
Thanks in advance!
A
Fileobject isn’t a real file at all – it’s really just a filename/location, and methods which hook into the file system to check whether or not the file really exists etc. There’s no content directly associated with theFileinstance – it’s not like it’s a virtual in-memory file, for example. The instance itself is just an object in memory like any other object.Creating a
Fileinstance on its own does nothing to the file system.When you create a
FileOutputStream, however, that does affect whatever file system you’re writing to. TheFileinstance is relatively irrelevant though – you’d get the same effect from: