欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

回顾inputstream和outputstream

发布时间:2025/5/22 编程问答 38 豆豆
生活随笔 收集整理的这篇文章主要介绍了 回顾inputstream和outputstream 小编觉得挺不错的,现在分享给大家,帮大家做个参考.
@RequestMapping("input")public void input() throws IOException {File file=new File("D:"+ File.separator+"test.txt");InputStream in=new FileInputStream("D:"+ File.separator+"test.txt");//字节转字符 防止乱码InputStreamReader re=new InputStreamReader(in,"gbk");char[] b= new char[1024];int length;length= re.read(b);System.out.println(length);System.out.println(new String(b,0,length));}@RequestMapping("out")public void out(){try {String str="asdfghj欢迎来来到输出流 写入";char[] len=str.toCharArray();byte[] len1=str.getBytes();FileOutputStream in=new FileOutputStream("D:"+ File.separator+"test.txt");//字节转字符 防止乱码OutputStreamWriter wr=new OutputStreamWriter(in,"gbk");wr.write(len,0,len.length);wr.close(); //记得要关闭,否则无效果} catch (FileNotFoundException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}}

总结

以上是生活随笔为你收集整理的回顾inputstream和outputstream的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。