使用java 程序创建格式为utf-8文件的方法(写入和读取json文件)
使用java 程序创建格式为utf-8文件的方法:
try{
File file=new File("C:/11.jsp");
OutputStream out=new FileOutputStream(file);
BufferedWriter rd = new BufferedWriter(new OutputStreamWriter(out,"utf-8"));
rd.write("333333333333中国");
rd.close();
out.close();
}catch(IOException e){
e.printStackTrace();
}
//判断文件是否存在
//(获取服务器的config下的路径)
File fileExit = new File(this.getClass().getClassLoader().getResource(path).toURI().getPath());
if(!fileExit.exists()){
return fileContent;
}
//(获取webroot下文件路径)
ServletContext sctx = ServletActionContext.getServletContext();
String path = sctx.getRealPath("/");// 服务器文件路径
File filePath=new File("uploadfiles/temp/"+"2016-11-09");//拼接文件路径
String fileContent = "";
InputStreamReader file = new InputStreamReader(
IGetEshopid.class.getClassLoader()
.getResourceAsStream(path), "UTF-8");
BufferedReader reader = new BufferedReader(file);
String tempString = null;
while ((tempString = reader.readLine()) != null) {
fileContent += tempString;
}
reader.close();
return fileContent;
最新文章
- 如何设置ASP.NET页面的运行超时时间 (转载)
- 提高sevenzipsharp 检查密码的速度(1)
- 读Lua游戏开发实践指南
- 【VLC-Android】vlc-android简例
- 《浅谈磁盘控制器驱动》,磁盘控制器驱动答疑解惑![2012.1.29完结]by skyfree
- UVa 二叉树重建(先序+中序求后序)
- java攻城狮之路(Android篇)--ListView与ContentProvider
- Altium Designer哪里下载和导入元件库_图文教程
- Codeforces Round #260 (Div. 1) A. Boredom (简单dp)
- IEEE二进制浮点数算术标准(IEEE 754)
- [转] 考验你的JavaScript底细
- Hibernate二 映射 注解 一级缓存
- html5 手机APP计算高度问题
- [Cycle.js] Generalizing run() function for more types of sources
- java系列--集合
- linux下启动tomcat----Cannot find ./catalina.sh
- 在CMainFrame里使用定时器是有讲究的
- 21_Android中常见对话框,光传感器,通过重力感应器编写出指南针应用,帧动画,通过Jav代码的方式编写补间动画,通过XML的方式编写补间动画
- 通过反射实现get和set方法
- Pandas系列(三)-缺失值处理