首页 > 移动平台 > 详细

android file path

时间:2015-05-05 21:26:58      阅读:177      评论:0      收藏:0      [点我收藏+]

问题 出现的异常为:java.lang.IllegalArgumentException: File /mnt/sdcard/crazyit.bin contains a pathseparator。

 

主要是由于在打开文件的输出流时使用的openFileOutput()方法的第一参数用于指定文件名称,不能包含路径分隔符“/”
解决方法   //       FileInputStream fis =
openFileInput(sdCardDir.getCanonicalPath()+FILE_NAME);改为                FileInputStream fis = new
FileInputStream(sdCardDir.getCanonicalPath()+FILE_NAME)

 

 

对于InputStream的读取有两种方法

1.inputstream---》byte---》String

 

2.inputstream--->inputstreamReader---->BufferedRead-->string

 

android之sd文件读取模块

FileInputStream fileInputStream = null;
        try {
            File file = new File(Environment.getExternalStorageDirectory()
                    + "/wipe.txt");

            if (!file.exists())
                file.createNewFile();
            fileInputStream = new FileInputStream(file);
            BufferedReader bufferedReader = new BufferedReader(
                    new InputStreamReader(fileInputStream));
            String temapp;

            while ((temapp = bufferedReader.readLine()) != null) {

                apps.add(temapp);
                Toast.makeText(MainActivity.this, temapp, Toast.LENGTH_LONG)
                        .show();
            }
            bufferedReader.close();

        } catch (FileNotFoundException e) {
            // TODO 自动生成的 catch 块
            e.printStackTrace();
        } catch (IOException e) {
            // TODO 自动生成的 catch 块
            e.printStackTrace();
        } finally {
            if (fileInputStream != null)
                try {
                    fileInputStream.close();
                } catch (IOException e2) {
                    // TODO: handle exception
                    e2.printStackTrace();
                }
        }

android file path

原文:http://www.cnblogs.com/lzh-Linux/p/4480010.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!