回顾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