android向sd卡写文件|android44 app向sd卡中写数据需要什么权限

1. android4.4 app向sd卡中写数据需要什么权限

需要写入SD卡的权限:在AndroidManifest.xml文件中的<manifest></manifest>标签之间加入以下内容:

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

第一行是读取数据的权限,第版二行是写入权数据的权限,根据需要使用。(答题不易,正确请采纳)

2. android 如何实现添加保存数据到SD卡里面

importjava.io.FileOutputStream;importandroid.os.Bundle;importandroid.os.Environment;importandroid.widget.Toast;importandroid.app.Activity;{@OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);if(isHavedSDcard()){try{writeStr2SDCard("Helloworld!!!");}catch(Exceptione){e.printStackTrace();}}else{showToast("您的手机没有内存卡哦!");}}/***判断是否有SDcard**@returntrue-有,false-无*@authorJunhui*/publicbooleanisHavedSDcard(){if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))returntrue;elsereturnfalse;}/***获取SDcard根目录**/publicStringgetRootPath(){returnEnvironment.getExternalStorageDirectory().toString();}/***toast提示**@paramtext*-提示内容*@authorJunhui*/publicvoidshowToast(Stringtext){Toast.makeText(this,text,Toast.LENGTH_SHORT).show();}privatevoidwriteStr2SDCard(Stringstr)throwsException{FileOutputStreamfos=newFileOutputStream(getRootPath()+"/test.txt");fos.write(str.getBytes());}}

用我这段代码试下,加了注释的,很好看懂。对了,别忘记在AndroidManifest.xml加上

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

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

哦。

3. 怎么往android模拟器的sd卡里写一个mp3文件呢,我用导入为什么导入不进去呢

向SD卡中写一个文件两种方法:一种方法 直接用DDMS手动导入 文件名不能有中文 大写英文二种方法 使用代码,用文件流进行写入 先将要导入的文件放在项目的assets目录下 public String getSDPath(String fileNames) { //在SD中新建一个MP3文件 fileNames参数为文件名File sdDir = null; // 判断sd卡是否存在boolean sdCardExist = Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED); if (sdCardExist) {System.out.println("sd卡存在");sdDir = Environment.getExternalStorageDirectory();// 获取跟目录}String fileName = sdDir.toString() + fileNames;return fileName;} /* * 拷贝文件到SD中 * filePath assets中文件路径 */public String mergeFile(Context c, String filePath, String dst) {File fileone = new File(dst);System.out.println("dst文件是否存在" + fileone.exists());if (!fileone.exists()) {OutputStream out;try {out = new FileOutputStream(dst);byte[] buffer = new byte[1024];InputStream in;int readLen = 0;// 获得输入流 ,注意文件的路径 此文件路径为在程序的assets目录下in = c.getAssets().open(filePath);while ((readLen = in.read(buffer)) != -1) {out.write(buffer, 0, readLen);}out.flush();in.close();// 把所有小文件都进行写操作后才关闭输出流,这样就会合并为一个文件了out.close();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}System.out.println("dst 文件路径 : " + dst);return dst;}最后调用上面的方法 mergeFile(this,“要导入的MP3文件路径”,getSDPath(“SD卡内新文件路径”))

4. 如何给Android虚拟机的sd卡导入文件

如果你有eclipse的话,切换到DDMS模式,在选中fileexplorer选项卡,在这里面你会看到一个按钮,画着一个向右的箭头和一部手机,点击它,选择你想要传送的文件就可以了

5. android 怎么写文件日志到SD卡上

android 如何写文件日志到SD卡上../*** 写文件到sd卡上* * @param context*/public void writeFileToSD(String context) {//使用RandomAccessFile 写文件 还是蛮好用的..推荐给大家使用…String sdStatus = Environment.getExternalStorageState();if (!sdStatus.equals(Environment.MEDIA_MOUNTED)) { Log.d("TestFile", "SD card is not avaiable/writeable right now."); return;}try { String pathName = "/sdcard/"; String fileName = "log.txt"; File path = new File(pathName); File file = new File(pathName + fileName); if (!path.exists()) {Log.d("TestFile", "Create the path:" + pathName);path.mkdir(); } if (!file.exists()) {Log.d("TestFile", "Create the file:" + fileName);file.createNewFile(); } RandomAccessFile raf = new RandomAccessFile(file, "rw"); raf.seek(file.length()); raf.write(context.getBytes()); raf.close(); //注释的也是写文件..但是每次写入都会把之前的覆盖.. /*String pathName = "/sdcard/"; String fileName = "log.txt"; File path = new File(pathName); File file = new File(pathName + fileName); if (!path.exists()) {Log.d("TestFile", "Create the path:" + pathName);path.mkdir(); } if (!file.exists()) {Log.d("TestFile", "Create the file:" + fileName);file.createNewFile(); } FileOutputStream stream = new FileOutputStream(file); String s = context; byte[] buf = s.getBytes(); stream.write(buf); stream.close();*/} catch (Exception e) { Log.e("TestFile", "Error on writeFilToSD.");}}

6. android 模拟器手机如何添加文件到sd卡

在DDMS中直接添加文件到模拟器sd卡如果出现错误类似:Failed to push XXXXX.txt on emulator- : Read-only file system的错误,原因是你的sdcard权限不够,需要直接创建一个SDCARD。一、首先创建SDCARD 我创建的sdcard名为:sdcard.img(名字随便取,以img后缀名结束)进入DOS 指向 目录 E:\android-sdk_r10-windows\android-sdk-windows\tools (这是安装android的SDK的文件里,配置这个环境变量的就不用了)我们在Dos里面输入 mksdcard -l sdcard 100M E:\sdcard\sdcard.img(这个文件的位置可以任意放在哪里)解说:1. sdcard命令可以使用三种尺寸:字节、K和M。如果只使用数字,表示字节。后面还可以跟K,如262144K,也表示256M。 2. sdcard建立的虚拟文件最小为8M,也就是说,模拟器只支持大于8M的虚拟文件。 3. -l命令行参数表示虚拟磁盘的卷标,可以没有该参数。 4. 虚拟文件的后缀.img可以在Dos里面 输入mksdcard Help 有说的二、创建好sdcard之后,我们要在模拟器加载sdcardWindow-》AVD Manager-》选中你使用的模拟器-》Edit然后在SD Card选项中选择File然后选择刚创建的sdcard.img,然后点击Edit AVD进行保存三、这时再向模拟器的sdcard中添加文件就没问题了(注意:这里最好是将模拟器重启一下)四、重启模拟器后,在模拟器中找到Dev Tools并启动,然后找到并运行 Media Scanner对新添加的文件进行扫描,显示 finished就可以退出了,这时候添加进去的文件就可以使用了(例如:MP3文件,这时音乐播放器就可以找到了)。

7. 如何给Android虚拟机的sd卡导入文件

您好,首先启动你的虚拟设备,然后打开一个DOS命令窗口。所有安装程序和添加的文件都是放在模拟器的 sdcard目录下,如果直接添加文件,以后文件多了会显得乱,所以最好在模拟器上分门别类的建好文件夹,再把对应的文件添加进去。1 在模拟器上建立目录:adb shell 调用shell远程操作模拟器ls 显示当前目录下的文件cd sdcard 进入sdcard目录mkdir mp4 建立 mp4 目录若提示Read-onlyfilesystem错误,退出adb shell 然后运行adb remount命令,即可。exit 退出模拟器2 添加当前Window目录下的文件到模拟器的 mp4文件夹中:adb push 文件名 /sdcard/mp4也可以整个目录下的文件一起添加,把此命令中的“文件名”改成你的“目录名”就可以了。3 此时文件已经添加过来了,我们还要在模拟器上操作一下才能播放。希望能帮到您,

8. android上如何实现后台日志记录并写文件到sd卡

android 如何写文件日志到SD卡上../*** 写文件到sd卡上* * @param context*/public void writeFileToSD(String context) {//使用RandomAccessFile 写文件 还是蛮好用的..推荐给大家使用…String sdStatus = Environment.getExternalStorageState();if (!sdStatus.equals(Environment.MEDIA_MOUNTED)) { Log.d("TestFile", "SD card is not avaiable/writeable right now."); return;}try { String pathName = "/sdcard/"; String fileName = "log.txt"; File path = new File(pathName); File file = new File(pathName + fileName); if (!path.exists()) {Log.d("TestFile", "Create the path:" + pathName);path.mkdir(); } if (!file.exists()) {Log.d("TestFile", "Create the file:" + fileName);file.createNewFile(); } RandomAccessFile raf = new RandomAccessFile(file, "rw"); raf.seek(file.length()); raf.write(context.getBytes()); raf.close(); //注释的也是写文件..但是每次写入都会把之前的覆盖.. /*String pathName = "/sdcard/"; String fileName = "log.txt"; File path = new File(pathName); File file = new File(pathName + fileName); if (!path.exists()) {Log.d("TestFile", "Create the path:" + pathName);path.mkdir(); } if (!file.exists()) {Log.d("TestFile", "Create the file:" + fileName);file.createNewFile(); } FileOutputStream stream = new FileOutputStream(file); String s = context; byte[] buf = s.getBytes(); stream.write(buf); stream.close();*/} catch (Exception e) { Log.e("TestFile", "Error on writeFilToSD.");}}

9. 怎样在安卓手机的存储卡里写文档保存在sd卡上

那你就下载个文件处理器es或者oi管理,把文件放过去就可以了

10. android4.4.2如何往外置sd卡根目录写文件

进入手机自带的文件管理器,里边有相关选项;如果是编程的话(首先要获取到sd卡的绝对路径,然后可以通过输出流实现文件拷贝)


赞 (0)