1

I want to read a file that is saved in my java folder (same where my activities are) in package com.example so it's java-->com.example--> data.ser. However I'm getting java.io.FileNotFoundException: /java/com/example/data.ser: open failed: ENOENT (No such file or directory) when I call

ObjectInputStream in = new ObjectInputStream(new FileInputStream(new File("java/com/example/data.ser")));. I tried removing the java part or just leaving the file name on its own but nothing works. I am not loading it from external/internal storage but just from within the app. How to do it? I'm using android studio. Thanks for help

Dodi
  • 2,201
  • 4
  • 30
  • 39
  • There is an Android way using the `res` folder for asset files, and there is a more "bare-bones" Java way that allows access to resource files added to the JAR / APK file. Android resources: http://developer.android.com/reference/android/content/res/Resources.html -- Java resources: http://docs.oracle.com/javase/tutorial/deployment/webstart/retrievingResources.html – tiguchi Jan 07 '15 at 16:30

1 Answers1

0

Files has to be stored on 'assets' or 'raw' folder, depending on what kind of file you are going to store. On 'java' you should set code class only. You can find an easy example here: raw file example

Community
  • 1
  • 1
pozuelog
  • 1,284
  • 13
  • 27