Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8340127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:05:35+00:00 2026-06-09T05:05:35+00:00

I need to save an object to public external storage ( http://developer.android.com/guide/topics/data/data-storage.html#filesExternal ) Please

  • 0

I need to save an object to public external storage (http://developer.android.com/guide/topics/data/data-storage.html#filesExternal) Please scroll down to “Saving files that should be shared” i.e. saving files such that it won’t get deleted if the app is uninstalled.

After saving it, I need to load the object back from the saved file and display it. Just using int object for testing purposes. Please help.

Here’s my code for saving and loading

int a = 1;
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()))
{
    String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString();
    final File file = new File (path, "int_object_saved.dat");

    FileOutputStream file_output_stream = null;
    ObjectOutputStream object_output_stream = null;
    boolean should_keep_file = true;

    try
    {
        file_output_stream = new FileOutputStream(file);
        object_output_stream = new ObjectOutputStream(file_output_stream);
        object_output_stream.writeObject(a);

    }
    catch (FileNotFoundException e)
    {
        e.printStackTrace();
        should_keep_file = false;
    }
    catch (IOException e)
    {
        e.printStackTrace();
        should_keep_file = false;
    }
    finally
    {
        try
        {
            if(object_output_stream != null)
                object_output_stream.close();

            if(file_output_stream != null)
                file_output_stream.close();

            if(!should_keep_file)
                file.delete();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}
else
{
    Log.d("mytag", "Sorry can't write to external media");
}

int b = 0;
try
{
    FileInputStream file_input_stream;
    file_input_stream = activity_parameter.openFileInput("int_object_saved.dat");
    ObjectInputStream object_input_stream = new ObjectInputStream(file_input_stream);
    b = (Integer) object_input_stream.readObject();
    object_input_stream.close();
}
catch (FileNotFoundException e)
{
    e.printStackTrace();
}
catch (OptionalDataException e)
{
    e.printStackTrace();
}
catch (ClassNotFoundException e)
{
    e.printStackTrace();
}
catch (IOException e)
{
    e.printStackTrace();
}

Log.d("mytag", Integer.toString(b));

This is the logcat I get

08-02 12:39:48.382: I/ApplicationPackageManager(13109): cscCountry is not German : BTU
08-02 12:39:48.421: D/mytag(13109): my Log is working :D
08-02 12:39:48.437: W/System.err(13109): java.io.FileNotFoundException: /data/data/j.violajones.facedetect1/files/int_object_saved.dat (No such file or directory)
08-02 12:39:48.437: W/System.err(13109): at org.apache.harmony.luni.platform.OSFileSystem.open(Native Method)
08-02 12:39:48.437: W/System.err(13109): at dalvik.system.BlockGuard$WrappedFileSystem.open(BlockGuard.java:232)
08-02 12:39:48.437: W/System.err(13109): at java.io.FileInputStream.<init>(FileInputStream.java:80)
08-02 12:39:48.437: W/System.err(13109): at android.app.ContextImpl.openFileInput(ContextImpl.java:416)
08-02 12:39:48.437: W/System.err(13109): at android.content.ContextWrapper.openFileInput(ContextWrapper.java:152) 
08-02 12:39:48.437: W/System.err(13109): at j.violajones.facedetect1.Detector.<init>(Detector.java:94) 
08-02 12:39:48.437: W/System.err(13109): at j.violajones.facedetect1.Camera_Activty.onCreate(Camera_Activty.java:72)
08-02 12:39:48.437: W/System.err(13109): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-02 12:39:48.437: W/System.err(13109): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
08-02 12:39:48.437: W/System.err(13109): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
08-02 12:39:48.437: W/System.err(13109): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-02 12:39:48.437: W/System.err(13109): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
08-02 12:39:48.437: W/System.err(13109): at android.os.Handler.dispatchMessage(Handler.java:99)
08-02 12:39:48.437: W/System.err(13109): at android.os.Looper.loop(Looper.java:130)
08-02 12:39:48.437: W/System.err(13109): at android.app.ActivityThread.main(ActivityThread.java:3687)
08-02 12:39:48.445: W/System.err(13109): at java.lang.reflect.Method.invokeNative(Native Method)
08-02 12:39:48.445: W/System.err(13109): at java.lang.reflect.Method.invoke(Method.java:507)
08-02 12:39:48.445: W/System.err(13109): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
08-02 12:39:48.445: W/System.err(13109): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
08-02 12:39:48.445: W/System.err(13109): at dalvik.system.NativeStart.main(Native Method)
08-02 12:39:48.445: D/mytag(13109): 0

and this is my AndroidManifest.xml file

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="j.violajones.facedetect1"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

    <uses-feature android:name="android.hardware.camera" />
    <uses-feature android:name="android.hardware.camera.autofocus" />

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="15" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".Camera_Activty"
            android:label="@string/title_activity_camera__activty"
            android:screenOrientation="landscape" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T05:05:37+00:00Added an answer on June 9, 2026 at 5:05 am

    Error message is clear:

    java.io.FileNotFoundException: /data/data/j.violajones.facedetect1/files/int_object_saved.dat (No such file or directory)
    

    You don’t have such a file at /data/data/j.violajones.facedetect1/files/int_object_saved.dat

    And indeed you don’t seem to be writing to that location because you use:

    String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString();
    final File file = new File (path, "int_object_saved.dat");
    

    So try to read from the location where you saved it:

    String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString();
    FileInputStream file_input_stream = new FileInputStream(path + "/int_object_saved.dat");
    /*...*/
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to parse string from datapicker to a DataTime object and save in
I need to save to an isolated storage the total time that the user
I need to save some classes and data structures to a file. My first
public void Save(object s, EventArgs e) { HtmlMeta meta = new HtmlMeta() { Name
I have a List <Hotel> object and I need to save it to a
I'm having an strange error when trying to save an object into isolated storage.
I don't know how to save object with where clause. I need it to
I need to save objects - instances of classes - in my app like
I am using jQuery to save the values of my javascript objects. I need
.txt file need save in SD-card. Save(n + String.valueOf(key) + .txt); private void Save(String

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.