Reputation: 1744
I'm trying to create a new file by:
File file = new File(this.getFilesDir(), "test.tmp");
After that I have the follwing code:
try {
fis = new BufferedInputStream(new FileInputStream(file));
ObjectInputStream ois = new ObjectInputStream(fis);
..... other not important code
And it throws the following error:
android.system.ErrnoException: open failed: ENOENT (No such file or directory)
regarding this line:
fis = new BufferedInputStream(new FileInputStream(file));
Isn't File file = new File(this.getFilesDir(), "test.tmp");
supposed to create the file?
Can you give me a clue? I know that I'm missing a small but important part here, but I'm unable to spot it.
Upvotes: 0
Views: 56
Reputation: 1006554
Isn't File file = new File(this.getFilesDir(), "test.tmp"); supposed to create the file?
No. It creates a Java object, an instance of class File
. It has no impact on the filesystem.
Use exists()
on the File
object to see if the file exists. Or, if for some reason you want the empty file there, call createNewFile()
on the File
object.
Upvotes: 3