java读取本地文件
File file = new File("F:/hejing/InstrumentJsonData.txt");
StringBuilder localStrBulider = new StringBuilder();
if(file.isFile() && file.exists()) {
try {
InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(file), "utf-8");
BufferedReader bufferReader = new BufferedReader(inputStreamReader);
String lineStr = null;
try {
while((lineStr = bufferReader.readLine()) != null) {
localStrBulider.append(lineStr);
}
bufferReader.close();
inputStreamReader.close();
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("file read error!");
e.printStackTrace();
}
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
System.out.println("file catch unsupported encoding!");
e.printStackTrace();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
System.out.println("file not found!");
e.printStackTrace();
}
}else {
System.out.println("file is not a file or file is not existing!");
return null;
}
System.out.println("localStrBulider.toString():" + localStrBulider.toString());

java读取本地文件的更多相关文章
- Java读取本地文件,并显示在JSP文件中
当我们初学IMG标签时,我们知道通过设置img标签的src属性,能够在页面中显示想要展示的图片.其中src的值,可以是磁盘目录上的绝对,也可以是项目下的相对路径,还可以是网络上的图片路径.在存 ...
- Java读取本地文件进行unicode解码
工具使用: package test.opservice; import eh.util.MapValueUtil; import java.io.BufferedReader; import jav ...
- Java读取本地文件(输入流)
package cn.buaa; import java.io.File; import java.io.FileInputStream; import java.io.FileReader; imp ...
- java 读取本地文件并转换为byte数组
private byte[] InputStream2ByteArray(String filePath) throws IOException { InputStream in = new File ...
- java 中读取本地文件中字符
java读取txt文件内容.可以作如下理解: 首先获得一个文件句柄.File file = new File(); file即为文件句柄.两人之间连通电话网络了.接下来可以开始打电话了. 通过这条线路 ...
- JAVA读取XML文件并解析获取元素、属性值、子元素信息
JAVA读取XML文件并解析获取元素.属性值.子元素信息 关键字 XML读取 InputStream DocumentBuilderFactory Element Node 前言 最 ...
- .NET 读取本地文件绑定到GridViewRow
wjgl.aspx.cs: using System; using System.Collections; using System.Configuration; using System.Data; ...
- java分享第十六天( java读取properties文件的几种方法&java配置文件持久化:static块的作用)
java读取properties文件的几种方法一.项目中经常会需要读取配置文件(properties文件),因此读取方法总结如下: 1.通过java.util.Properties读取Propert ...
- 前台JS(type=‘file’)读取本地文件的内容,兼容各种浏览器
[自己测了下,能兼容各种浏览器,但是读取中文会出现乱码.自己的解决方法是用notepad++把txt文件编码改为utf-8(应该是和浏览器编码保持一致吧?..)] 原文 http://blog.cs ...
随机推荐
- 【c语言】不用大与小与号,求两数最大值
// 不用大与小与号,求两数最大值 #include <stdio.h> int max(int a, int b) { int c = a - b; int d = 1 << ...
- Gherkin关键字
Feature 功能 Background 背景 Scenario 场景 Outline Scenarios(or Examples) Given 假如.假设.假定 When 当 Then 那么 An ...
- bye 2013 hello 2014
最近两个月除了必要的工作外,其余时间都在干一些我其实平时很少干的事, 喝酒.唱歌.打麻将.玩牌.以及到处跑找朋友玩,也许是过年的原因我放纵了自己,也许是自己心中的烦恼.我的博客记录着我每次看书学习的笔 ...
- Mac OS X中配置Apache后提示You don't have permission to access / on this server
根据这篇博客http://www.cnblogs.com/snandy/archive/2012/11/13/2765381.html,在mac系统中,配置的apache,配置完成后,提示 You d ...
- go项目布局(摘录)
go的项目结构布局 或 包结构布局 这一块大家似乎还在摸索吧, 常用的应该还是类似于java的mvc布局, 但网上也有不同的布局方式,查阅github上的一些源码,也有大量的采用. 我把自己碰到的资料 ...
- 自己学Docker:4.開始了解Docker的工作模式
上一章在学习中有2个疑问: 怎样保存我们在容器里的改动? 假设apt-get假设不能安装时,怎样在Docker中安装软件? 关于run创建的容器问题 对于第一个问题.原来每次运行(当非root用户时, ...
- LwIP协议栈(2):网络接口
在LwIP中,物理网络硬件接口结构保存在一个全局链表中,它们通过结构体中的 next 指针连接. struct netif { /// pointer to next in linked list * ...
- Atitit.木马病毒 webftp 的原理跟个设计
Atitit.木马病毒 webftp 的原理跟个设计 ftp木马的效果 文件传播 文件列表 文件内容查看 作者:: ★(attilax)>>> 绰号:老哇的爪子 ( 全名::Att ...
- 美团HD(7)-添加取消搜索按钮
DJSelectCityViewController.m #pragma mark - UISearchBar 代理方法 /** SearchBar开始编辑 */ - (void)searchBarT ...
- [精]Oracle 11G数据库VMware虚拟机下载
虚拟机文件下载地址: http://pan.baidu.com/s/1pJL5Tub 备份一个防止失效 https://pan.baidu.com/s/1nvbZQad Readme文件: 数据库版本 ...