使用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();
}java
//判断文件是否存在web
//(获取服务器的config下的路径)
File fileExit = new File(this.getClass().getClassLoader().getResource(path).toURI().getPath());
if(!fileExit.exists()){
return fileContent;
}服务器
//(获取webroot下文件路径)jsp
ServletContext sctx = ServletActionContext.getServletContext();
String path = sctx.getRealPath("/");// 服务器文件路径
File filePath=new File("uploadfiles/temp/"+"2016-11-09");//拼接文件路径this
String fileContent = "";
InputStreamReader file = new InputStreamReader(
IGetEshopid.class.getClassLoader()
.getResourceAsStream(path), "UTF-8");
BufferedReader reader = new BufferedReader(file);utf-8
String tempString = null;
while ((tempString = reader.readLine()) != null) {
fileContent += tempString;
}
reader.close();
return fileContent;get