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

  • SEARCH
  • Home
  • 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 8236749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:13:59+00:00 2026-06-07T19:13:59+00:00

I’m writing a testing program and I want to serialize some of my test

  • 0

I’m writing a testing program and I want to serialize some of my test result to a file. I keep on getting this annoying permission denied exception. To make things easier, I write a small sample code and still get the same permission denied warning. Here is my code, I use getExternalStorageDirectory to get the /mnt/sdcard/ directory:

private void writetry(){
        try {
            File sdCard = Environment.getExternalStorageDirectory();
            Log.d("can write", String.valueOf(sdCard.canWrite()));
            Log.d("ExternalStorageState", Environment.getExternalStorageState());
            File file = new File(sdCard, "VisitedScreen.temp");
            //file.createNewFile();
            FileOutputStream f = new FileOutputStream(file);
             byte[] buf = "Hello".getBytes();
             f.write(buf);
             f.close();
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

And here is what logcat print out:

07-12 12:28:47.288: D/can write(253): false
07-12 12:28:47.288: D/ExternalStorageState(253): mounted
07-12 12:28:47.297: W/System.err(253): java.io.FileNotFoundException: /sdcard/VisitedScreen.temp
07-12 12:28:47.437: W/System.err(253):  at org.apache.harmony.luni.platform.OSFileSystem.open(OSFileSystem.java:244)
07-12 12:28:47.437: W/System.err(253):  at java.io.FileOutputStream.<init>(FileOutputStream.java:97)
07-12 12:28:47.437: W/System.err(253):  at java.io.FileOutputStream.<init>(FileOutputStream.java:69)

I declared my Junit testing Manifest file as: (Actually it’s the wrong place to set the permission)

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="net.mandaria.tippytipper.test"
    android:versionCode="1"
    android:versionName="1.0" >
    <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="7" />

    <instrumentation
        android:name="android.test.InstrumentationTestRunner"
        android:targetPackage="net.mandaria.tippytipper" />

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

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <uses-library android:name="android.test.runner" />
    </application>


</manifest>

Any suggestion is appreciated!

Added: I copy the same code to a normal android program, it works, and the sdCard.canWrite() return true. But in Android Junit testing project it’s not working. Anyone knows why??

Problem solved: Thanks for all those of you have replied. It’s because I haven’t add the in original Android program. I also noted that I don’t need to add any permission to Junit test project. It’s very interesting that the write action happened in the testing project, but permission is required in the original project. I’m wondering what if I’m doing black box testing against an .apk file. I can’t change the permission from the byte code right?

  • 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-07T19:14:02+00:00Added an answer on June 7, 2026 at 7:14 pm

    The uses-permission

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

    should be added to your main project’s manifest. Remember that tests are run in the same process as the main application.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
i want to parse a xhtml file and display in UITableView. what is the
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,

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.