将String字符串写到本地文件的方法

编程入门 行业动态 更新时间:2024-10-27 20:37:19

将String字符串<a href=https://www.elefans.com/category/jswz/34/1733604.html style=写到本地文件的方法"/>

将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字符串写到本地文件的方法

本文发布于:2024-03-08 19:37:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1722076.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:写到   字符串   本地文件   方法   String

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!