Answer the question
In order to leave comments, you need to log in
Runtime.getRuntime().exec: why doesn't "cp" command work everywhere?
Good afternoon!
There is this code:
File dir = Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_DOWNLOADS );
File src = new File(dir, "test.dat");
File dst = new File(dir, "test_2.dat");
if ( src.exists() )
{
try
{
Process process = Runtime.getRuntime().exec( new String[] {"cp", "-f", src.getAbsolutePath(), dst.getAbsolutePath()} );
process.waitFor();
}
catch (IOException e)
{
e.printStackTrace();
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
Answer the question
In order to leave comments, you need to log in
Understood. It turns out that there was no "cp" command on that tablet:
/system/bin/sh: cp: not found
Replaced with the "dd" command:
Runtime.getRuntime().exec( new String[] {"dd", "if=" +src.getAbsolutePath(), "of="+dst.getAbsolutePath()} )
it's better to do "busybox cp ..."
for embedded systems, the entire toolchain is implemented through a single executable file - busybox.
it implements all the required functionality.
all other utilities are obtained by creating a hardlink to it (if busybox is called cp, then it will behave like cp).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question