-1

我正在将用户的声音录制到外部存储器中。但如果用户在手机中没有 SD 卡。录制的文件应该保存到内部存储器中。

static final String PREFIX = "record";
static final String EXTENSION = ".3gpp";

if (file == null) {
                File rootDir = Environment.getExternalStorageDirectory();
                file = File.createTempFile(PREFIX, EXTENSION, rootDir);
            }

如何将相同的文件保存到内部存储器?

提前谢谢!!!!

4

2 回答 2

0

您必须首先检查外部存储卡的可用性。如果可用,那么您可以将文件保存在其中。其他在手机内存中。

这是您使用内部存储的方式:

String FILENAME = "hello_file";
String string = "hello world!";

FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
fos.write(string.getBytes());
fos.close(); 

检查外部存储的可用性:

boolean mExternalStorageAvailable = false;
boolean mExternalStorageWriteable = false;
String state = Environment.getExternalStorageState();

if (Environment.MEDIA_MOUNTED.equals(state)) {
    // We can read and write the media
    mExternalStorageAvailable = mExternalStorageWriteable = true;
} else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
    // We can only read the media
    mExternalStorageAvailable = true;
    mExternalStorageWriteable = false;
} else {
    // Something else is wrong. It may be one of many other states, but all we need
    //  to know is we can neither read nor write
    mExternalStorageAvailable = mExternalStorageWriteable = false;
}

有关更多信息,查看

于 2013-02-07T10:27:03.003 回答
-1
  Try this:

   File rootDir = Environment.getExternalStorageDirectory();

   rootDir.mkdir();

   try {
    output=File.createTempFile(PREFIX, EXTENSION, rootDir);
} catch (IOException e1) {
   e1.printStackTrace();
}
于 2013-02-07T10:18:53.177 回答