本文实例讲述了java基于io流读取文件的方法。分享给大家供大家参考,具体如下:
public static void readfile(){ string pathstring = test.class.getresource("/simu").getfile(); try { pathstring = urldecoder.decode(pathstring, "utf-8"); } catch (unsupportedencodingexception e1) { e1.printstacktrace(); } system.out.println(pathstring); file file = new file(pathstring,"test.txt"); inputstream is = null; try { is = new fileinputstream(file); } catch (exception e) { e.printstacktrace(); } bufferedreader br = new bufferedreader(new inputstreamreader(is)); stringbuffer sb = new stringbuffer(""); string b = ""; try { while((b=br.readline())!=null){ sb.append(b).append("\n"); } } catch (exception e) { e.printstacktrace(); } string bb = sb.tostring(); system.out.println(bb); }
希望本文所述对大家java程序设计有所帮助。
如对本文有疑问, 点击进行留言回复!!
[杭电多校2020]第一场 1004 Distinct Sub-palindromes
Swift -- 将本地生成的UIImage进行持久化保存(存到文件中fileManager.createFile)
网友评论