写到本地文件的方法"/>
将String字符串写到本地文件的方法
闲着无事,记一下String写入本地文件的方法,直接上代码:
/*** 保存文件到本地* * @param urlString* @param filename* @param savePath* @throws Exception*/public static void writeOcrStrtoFile(String result, String outPath, String outFileName) throws Exception {File dir = new File(outPath);if(!dir.exists()) {dir.mkdirs();}File txt = new File(outPath + "/" + outFileName);if (!txt.exists()) {txt.createNewFile();}byte bytes[] = new byte[512];bytes = result.getBytes();int b = bytes.length; // 是字节的长度,不是字符串的长度FileOutputStream fos = new FileOutputStream(txt);
// fos.write(bytes, 0, b);fos.write(bytes);fos.flush();fos.close();}
更多推荐
将String字符串写到本地文件的方法
发布评论