第143页 5.2.5 External storage via an SD card
byhard (byhard.com)
- 章节名:5.2.5 External storage via an SD card
- 页码:第143页
续: //找到SD卡的路径。 File sdDir = Environment.getExternalStorageDirectory(); //创建文件夹 if (sdDir.exists() && sdDir.canWrite()) { File uadDir = new File(sdDir.getAbsolutePath() + "/unlocking_android"); uadDir.mkdir(); //创建文件 if (uadDir.exists() && uadDir.canWrite()) { File file = new File(uadDir.getAbsolutePath() + "/" + fileName); try { file.createNewFile(); } catch (IOException e) { // log and or handle } //写文件 if (file.exists() && file.canWrite()) { FileOutputStream fos = null; try { fos = new FileOutputStream(file); fos.write("I fear you speak upon the rack," + "where men enforced do speak " + "anything.".getBytes()); } catch (FileNotFoundException e) { 。。。 //读文件 File rFile = new File("/sdcard/unlocking_android/" + fileName); if (rFile.exists() && rFile.canRead()) { FileInputStream fis = null; try {fis = new FileInputStream(rFile); byte[] reader = new byte[fis.available()]; while (fis.read(reader) != -1) { } readOutput.setText(new String(reader)); 。。。 If you have static predefined data, you can use res/raw; if you have XML files, you can use res/xml. You can also work directly with the filesystem by creating, modifying, and retrieving data in files, either in the local internal filesystem or on the SD card, if one is available.
byhard对本书的所有笔记 · · · · · ·
-
第104页 4.1.1 Defining Intents
4.1.3 Adding external links to RestaurantFinder 打开一个网页: intent = new Intent(Inte...
-
第130页 chapter 5 Storing and retrieving data
5.1 Using preferences 5.1.1 Working with SharedPreferences 此数据文件写入data/data/[pac...
-
第143页 5.2.5 External storage via an SD card
说明 · · · · · ·
表示其中内容是对原文的摘抄