回顾inputstream和outputstream
生活随笔
收集整理的这篇文章主要介绍了
回顾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的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: java lList Map Set
- 下一篇: idea打包springboot项目为w