1.流的分类
提示
/** * 书写文件内容 */ public static void writeWord(String str) throws IOException { try ( FileOutputStream fileOutputStream = new FileOutputStream(URLDecoder.decode(path, "UTF-8")+"static\\system.txt"); // FileOutputStream fileOutputStream = new FileOutputStream("/usr/java/myfile/system.txt"); OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutputStream,"UTF-8"); PrintWriter out = new PrintWriter(outputStreamWriter); ){ out.write(str); out.flush(); } catch (IOException e) { e.printStackTrace(); throw new RuntimeException(e); } }
/** * 读取文件内容 */ public static String readWord () { try ( FileInputStream fileInputStream = new FileInputStream(URLDecoder.decode(path, "UTF-8")+"static\\system.txt"); // FileInputStream fileInputStream = new FileInputStream("/usr/java/myfile/system.txt"); InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream,"UTF-8"); BufferedReader br = new BufferedReader(inputStreamReader); ){ String line = null; StringBuffer sBuffer = new StringBuffer(); while((line = br.readLine())!=null){ sBuffer.append(line); } return sBuffer.toString(); } catch (IOException e) { e.printStackTrace(); throw new RuntimeException(e); } }
个人学习随笔,若是帮助到您,请给个推荐,或者评论一下下,谢谢了哟。若有不懂之处,请联系QQ:351094262(验证信息:博客园),原创不易,转载请标明出处!