How to execute "cd sdcard" command

by Karteek N » Thu, 22 Apr 2010 20:50:35 GMT

Sponsored Links
 Hi ,
I want to display what are the files and contents in sdcard through
I am able to print the root folder.But when i execute cd sdcard
it throws me exception that permission is denied.
When i did the same thing using adb shell i am able to display the sdcard.
Is there any way to change permissions like sudo

I used the following code to display root folder

 Runtime rt = Runtime.getRuntime();
          try {
                   Process process;
                          BufferedReader in =new BufferedReader(new

                         String line;
                         while ((line = in.readLine()) != null) {

                      } catch (Exception e) {

                   } catch (IOException e) {


But when change the above code like
  process=rt.exec("cd sdcard");
Its throws exception

Any help please


How to execute "cd sdcard" command

by Mark Murphy » Thu, 22 Apr 2010 20:53:06 GMT


Why don't you use Java file I/O?

Forking processes to read the output of things like ls is wasteful of
CPU, wasteful of memory, wasteful of battery life, and slow, when you
have alternatives. 

Mark Murphy (a Commons Guy)  | 

_The Busy Coder's Guide to Android Development_ Version 3.0


Sponsored Links

How to execute "cd sdcard" command

by Bob Kerns » Fri, 23 Apr 2010 00:40:27 GMT

 Mark points out all the reasons you shouldn't even be trying to do

But there's more! I assume you're going to take Mark's advice anyway,
but these are things that are likely to cause you trouble someday in
the future, so I'll point them out anyway.

First, you are trying to cd to some directory you have no reason to
believe exists. You don't have any idea what your current directory is
-- why should you expect it to have a 'sdcard' subdirectory? I expect
you meant "/sdcard" -- and that might work on your device. It might
not work on some other device, though. See this class for methods to
handle this cleanly: 
(You'll want to make use of this with Mark's advice, too).

And even if you did manage to cd to a directory named 'sdcard' -- it
would have NO EFFECT WHATSOEVER on the next command you execute!

You ran a shell and told it to do 'cd sdcard'. When it's done with
that, it exits. You no longer have a shell with that working
directory. Now you try to run 'ls' in a new shell. This new shell
doesn't care what you did in the old shell. It is NOT going to be
executing in your sdcard directory.

You could put these two commands into a .sh file, and execute that.
But what's the point? You could supply the same path directly to 'ls'.
Or even better, use the Java facilities for accessing the filesystem
and avoid all kinds of bugs you'd probably introduce -- like, for
example, handling spaces in filenames, etc.


How to execute "cd sdcard" command

by karteek » Fri, 23 Apr 2010 08:59:52 GMT

 hanks Marks,Bob.
Your help is really appreciated,
I will follow java i/o.

On Apr 22, 9:39pm, Bob Kerns <> wrote:
> >

Other Threads

1. EMMA code coverage


I read various lists and blogs regarding setting up EMMA to obtain
code coverage. I am TA-ing a software engineering class and it would
great to have the students measure code coverage. Unfortunately, it
seems EMMA is still in early development and there are still a few
problems setting it up.

I have a few questions:

Is there any alternative to EMMA?

Getting EMMA to work requires recompiling the SDK. Is it still the
case in 1.6?

The problem is that most of the students in the course will use
Windows and compiling Android on Windows is not supported.
If there is an easier way to get an EMMA enabled image, I would be
grateful if someone can post an updated tutorial for 1.6.

Alternatively, would it be possible to also link an EMMA enabled SDK
to the Android download page for Linux, Mac OS X and Windows?




2. how to load XML files dynamically

Hi Folks,

I need help on how to load XML  file dynamically in the code.I have an
activity and for the activity I have 5 xml layout files.I want to load
one of the XML file depending on the some logical condition.for e.g

case 1:
//load XML file 1
case 2:
//load XML file 2
case 3:
//load XML file 3


Please help me with some code snippet as i am new to the android



3. Basic Emma code coverage tutorial needed

4. ContentProvider's DB file access right problem when its android:multiprocess=true

5. removing item from ListView

6. OOT | vynil itu apa ya?

7. conditional build