zoukankan      html  css  js  c++  java
  • Android读取文本文件中内容的方法

     这几天在项目开发中,要读取文本文件中内容的,因此写了个读取文本文件中内容的方法,代码如下:

    //读取文本文件中的内容
        public static String ReadTxtFile(String strFilePath)
        {
            String path = strFilePath;
            String content = ""; //文件内容字符串
                //打开文件
                File file = new File(path);
                //如果path是传递过来的参数,可以做一个非目录的判断
                if (file.isDirectory())
                {
                    Log.d("TestFile", "The File doesn't not exist.");
                }
                else
                {
                    try {
                        InputStream instream = new FileInputStream(file); 
                        if (instream != null) 
                        {
                            InputStreamReader inputreader = new InputStreamReader(instream);
                            BufferedReader buffreader = new BufferedReader(inputreader);
                            String line;
                            //分行读取
                            while (( line = buffreader.readLine()) != null) {
                                content += line + "\n";
                            }                
                            instream.close();
                        }
                    }
                    catch (java.io.FileNotFoundException e) 
                    {
                        Log.d("TestFile", "The File doesn't not exist.");
                    } 
                    catch (IOException e) 
                    {
                         Log.d("TestFile", e.getMessage());
                    }
                }
                return content;
        }

  • 相关阅读:
    VB程序破解常用函数
    去VB程序NAG窗口方法-4C法
    error LNK2005: _DllMain@12 已经在 XXXX.obj 中定义
    汇编中的test和cmp指令
    OD保存修改后的数据到EXE
    C++ 异常捕获 try 和 __try的区别
    CListCtrl选中行
    WindowsAPI解析IAT地址
    Usaco 4.3.1 Buy Low, Buy Lower 逢低吸纳详细解题报告
    全国青少年信息学奥林匹克分区联赛(N)竞赛大纲
  • 原文地址:https://www.cnblogs.com/akira90/p/2763014.html
Copyright © 2011-2022 走看看