java 读取文件内容
2016-01-14 14:03
441 查看
//读取方法
public static String txt2String(String path){
String fileContent = "";
try
{
File f = new File(path);
if(f.isFile()&&f.exists())
{
InputStreamReader read = new InputStreamReader(new FileInputStream(f),"gbk");
BufferedReader reader=new BufferedReader(read);
String line;
while ((line = reader.readLine()) != null)
{
fileContent += line;
}
read.close();
}
} catch (Exception e)
{
e.printStackTrace();
}
return fileContent;
}
//测试main方法
public static void main(String[] args) {
String a=txt2String("C:/Users/A12080084/Desktop/Test.html");
System.out.println(a);
System.out.println(a.length());
}
public static String txt2String(String path){
String fileContent = "";
try
{
File f = new File(path);
if(f.isFile()&&f.exists())
{
InputStreamReader read = new InputStreamReader(new FileInputStream(f),"gbk");
BufferedReader reader=new BufferedReader(read);
String line;
while ((line = reader.readLine()) != null)
{
fileContent += line;
}
read.close();
}
} catch (Exception e)
{
e.printStackTrace();
}
return fileContent;
}
//测试main方法
public static void main(String[] args) {
String a=txt2String("C:/Users/A12080084/Desktop/Test.html");
System.out.println(a);
System.out.println(a.length());
}
相关文章推荐
- Git@OSC通过Eclipse生成SSH keys RSA公钥私钥
- struts2验证-validation
- eclipse加载大项目卡死问题
- java 将代理对象保存到本地文件
- 关于Java的异常
- [Spring MVC - 2A] - java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
- Java回调的简单理解
- [问答系列一]Java基础知识
- 简单东西-Java不变类编写
- Java字符串常量池的问题
- Spring MVC 的请求参数获取的几种方法
- struts2的DevMode模式
- struts2 配置文件的理解
- JAVA 监控内容收集之 Jmxtrans Agent
- 【Android Studio】Android Studio安装时提示找不到JDK
- Java Web开发技术应用——过滤器
- Java我的高效编程之环境搭建
- Java学习笔记
- Java回调理解 (step by step)
- spring配置dbcp链接数据库