- 将html文件读取然后进行存储
InputStream input1 = new FileInputStream(“F:/456123.html”);
ByteArrayOutputStream output = new ByteArrayOutputStream();
int temp = 0;
while ((temp = input1.read()) != -1) {
output.write(temp);
}
String s = output.toString();
- 将s进行存储,需要将其转成utf-8才可以
String remsgss = URLEncoder.encode(s, “utf-8”);
-读取数据
String content = new String(res.getBlob(“B_INPUT”).getBytes((long)1, (int)res.getBlob(“B_INPUT”).length()),“utf-8”);
-将读出的数据转换,因为我们存入的是utf-8,读出来需要解析
String strUTF8 = URLDecoder.decode(content, “utf-8”);
-ps:额外补充,因为html中含有需要转移的字符/,我们可以将/转变成*然后给前段传递
String s = strUTF8.replaceAll(“/”, “*”);
-如果不进行utf-8转换存储会发生如下错误
- ps:补充 数据读取和写入代码
-
InputStream input1 = new FileInputStream("F:/456123.html"); ByteArrayOutputStream output = new ByteArrayOutputStream(); int temp = 0; while ((temp = input1.read()) != -1) { output.write(temp); } String s = output.toString(); byte[] bytes = output.toByteArray(); FileOutputStream fileOutputStream; fileOutputStream = new FileOutputStream("F:/xxxxx.html"); fileOutputStream.write(bytes);