zoukankan      html  css  js  c++  java
  • android file path

    问题 出现的异常为: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();
                    }
            }

  • 相关阅读:
    04Windows频繁打开和关闭端口可能引发的问题 | 07.杂项
    04WebFinger的利用 | 02.技术预研 | Social
    Hunch:自动问答和决策机
    03PubSubHubbub 和 twisted 的 Persistent connections 能力 | 07.杂项 | Python
    01获取 Twitter User Profile 的三条路径 | 07.杂项
    大中华之事件监测
    一个如此简单的杀手级应用
    07爬虫的多线程调度 | 01.数据抓取 | Python
    02Twisted 构建 Web Server 的 Socket 长链接问题 | 07.杂项 | Python
    关于Cutt.com关于Topic Engine
  • 原文地址:https://www.cnblogs.com/lzh-Linux/p/4480010.html
Copyright © 2011-2022 走看看