Android中读取文本文件中内容的方法
2013-09-13 15:38
288 查看
这几天在项目开发中,要读取文本文件中内容的,因此写了个读取文本文件中内容的方法,代码如下:
//读取文本文件中的内容
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;
}
原文:/article/4874591.html
//读取文本文件中的内容
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;
}
原文:/article/4874591.html
相关文章推荐
- Android读取文本文件中内容的方法
- Android中读取文本文件中内容的方法
- Android中读取文本文件中内容的方法
- PowerShell读取文本文件指定行内容的方法
- android按行读取文件内容的几个方法
- android按行读取文件内容的几个方法
- Android 读取文件内容实现方法总结
- 读取Android Assets文本文件中的内容
- Android学习札记10:用SAX解析XML文件时,当标签中出现换行符时可能出现读取内容为空的解决方法
- Android下一种打开并读取指定路径文件内容的方法
- android UI(内容)更新的方法之handler、runOnUiThread()
- 读取nutch爬取内容方法
- iOS学习笔记21—从文本文件中读取内容到字符串里
- J2ME中有没有方法读取SIM卡中的内容?
- Android 聊天界面背景图片不顶上去内容顶上去解决方法
- 读取文本文件的最常用方法
- Android读取文本文件
- Android之横竖屏切换内容丢失问题解决方法
- Android将doc内容转为htm用webview显示出来的方法
- JAVA中读取文件(二进制,字符)内容的方法总结