把文件内容读出到一个字符串
2013-09-01 21:48
375 查看
view plaincopy to clipboardprint?
public String getinfo(String path)
{
File file;
String str="";
FileInputStream in;
try{
//打开文件file的InputStream
file = new File(path);
in = new FileInputStream(file);
//将文件内容全部读入到byte数组
int length = (int)file.length();
byte[] temp = new byte[length];
in.read(temp, 0, length);
//将byte数组用UTF-8编码并存入display字符串中
str = EncodingUtils.getString(temp,TEXT_ENCODING);
//关闭文件file的InputStream
in.close();
}
catch (IOException e) {
DisplayToast(e.toString());
}
return str;
}
public String getinfo(String path)
{
File file;
String str="";
FileInputStream in;
try{
//打开文件file的InputStream
file = new File(path);
in = new FileInputStream(file);
//将文件内容全部读入到byte数组
int length = (int)file.length();
byte[] temp = new byte[length];
in.read(temp, 0, length);
//将byte数组用UTF-8编码并存入display字符串中
str = EncodingUtils.getString(temp,TEXT_ENCODING);
//关闭文件file的InputStream
in.close();
}
catch (IOException e) {
DisplayToast(e.toString());
}
return str;
}
public String getinfo(String path)
{
File file;
String str="";
FileInputStream in;
try{
//打开文件file的InputStream
file = new File(path);
in = new FileInputStream(file);
//将文件内容全部读入到byte数组
int length = (int)file.length();
byte[] temp = new byte[length];
in.read(temp, 0, length);
//将byte数组用UTF-8编码并存入display字符串中
str = EncodingUtils.getString(temp,TEXT_ENCODING);
//关闭文件file的InputStream
in.close();
}
catch (IOException e) {
DisplayToast(e.toString());
}
return str;
}
public String getinfo(String path)
{
File file;
String str="";
FileInputStream in;
try{
//打开文件file的InputStream
file = new File(path);
in = new FileInputStream(file);
//将文件内容全部读入到byte数组
int length = (int)file.length();
byte[] temp = new byte[length];
in.read(temp, 0, length);
//将byte数组用UTF-8编码并存入display字符串中
str = EncodingUtils.getString(temp,TEXT_ENCODING);
//关闭文件file的InputStream
in.close();
}
catch (IOException e) {
DisplayToast(e.toString());
}
return str;
}
相关文章推荐
- 通过脚本的方式杀tomcat进程(shell脚本),shell中将一个文件的内容读出赋值给一个变量
- FATFS文件系统打开一个文件并读出内容
- 002_010 Python 处理字符串中的Zip文件 你的程序收到了一个字符串,内容是一个ZIP文件,需要读取zip文件的信息
- java写一个程序,实现从文件中读出文件内容,并将其打印在屏幕当中,并标注上行号
- 将字符串写入文件并把其内容读出
- 一个模式字符串,一个替换用字符串,以及两个文件名 它应该读取第一个文件, 并将内容写入第二个文件
- 写入出字符串到一个文件而不覆盖原文件的内容(追加)
- Java IO把一个文件中的内容以字符串的形式读出来
- 《编写一个程序,从一个文件中读出字符串,并显示在屏幕上》
- 【题目】在一个文件里面写入“我有1支铅笔,但是仓库里面有353628支”,读出刚才的文件内容,将1变为一,以此类推,写入新的文件。 新文件内容应为“我有一支铅笔,但是仓库里面有三五三六二八支”
- 在一个文件夹中查找内容包含某一字符串的文件
- 将一个文件中的内容存储在一个String字符串中
- C键盘输入一行字符,写入一个文件,再把该文件内容读出显示在屏幕上。
- 判断一个文件夹下的txt文件内部字符串 和另外一个txt每一行的字符串比较得到的内容
- 在一个页面上,一块区域上显示另一个页面(或者文件)的内容
- Demo:把文件内容读入一个String
- file标签之act=read(只需一行代码读出文件内容)
- linux 下从文件内容来识别一个文件类型的实例
- 写文件 :数组,字典,字符串, NSData 都有同一个 writeToFile 方法写入文件
- C++读取文件所有内容+写一个新文件