public static void main(String[] args) throws IOException { Writer writer = null; try{ String content = "种瓜得瓜种豆得豆";//要写入的字符串 File file = new File("D://1.txt");//创建文件的地址 writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file),"UTF-8")); writer.write(content); writer.flush(); } catch (IOException e) { e.printStackTrace(); }finally { if(writer != null){ writer.close(); } } }
将字符串写入文件出现中文乱码的解决办法
于 2018-05-31 16:53:46 首次发布