我想在SD卡上创建一个文件,然后在其中保存一个CSV文件。
从冲浪中我发现,似乎有两种方法可以解决这个问题:
http://developer.android.com/guide/topics/data/data-storage.html#filesExternal
如果您使用的是API级别8或更高级别,请使用getExternalFilesDir()打开一个文件,该文件表示应保存文件的外部存储目录。 此方法采用type参数指定所需的子目录类型,例如DIRECTORY_MUSIC和DIRECTORY_RINGTONES(传递null以接收应用程序文件目录的根目录)。
如果您使用的是API级别7或更低级别,请使用getExternalStorageDirectory()打开表示外部存储根目录的文件。 然后,您应该将数据写入以下目录:
/安卓/数据//文件/
http://www.anddev.org/working_with_files-t115.html :
FileWriter f = new FileWriter("/sdcard/download/possible.txt");我应该用什么方式? 如果是第一个,如何编写我的应用程序以兼容API级别<= 7和> = 8? 第一种方式是否有一些很好的教程?
I want to create a file on the SD-Card and later save a CSV file in it.
From surfing around I noticed that there seem to be two ways about going about it:
http://developer.android.com/guide/topics/data/data-storage.html#filesExternal
If you're using API Level 8 or greater, use getExternalFilesDir() to open a File that represents the external storage directory where you should save your files. This method takes a type parameter that specifies the type of subdirectory you want, such as DIRECTORY_MUSIC and DIRECTORY_RINGTONES (pass null to receive the root of your application's file directory).
If you're using API Level 7 or lower, use getExternalStorageDirectory(), to open a File representing the root of the external storage. You should then write your data in the following directory:
/Android/data//files/
And http://www.anddev.org/working_with_files-t115.html :
FileWriter f = new FileWriter("/sdcard/download/possible.txt");What way should I use? If the first, how do I write my application to be compatible with both API level <=7 and >=8? Is there some good tutorial for doing it the first way?
最满意答案
好吧,如果您需要与API级别7及更低版本兼容,请使用getExternalStorageDirectory()方法。 另请注意,从API级别4开始,您必须请求写入SD卡的权限:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />Well if you need compatibility with API level 7 and lower, use getExternalStorageDirectory() method. Also note that staring from API level 4 you have to request permission to write onto SD card:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />更多推荐
文件,API,http,电脑培训,计算机培训,IT培训"/> <meta name="description"
发布评论