Java基于IO流读取文件的方法
程序员文章站
2024-03-06 13:16:02
本文实例讲述了java基于io流读取文件的方法。分享给大家供大家参考,具体如下:
public static void readfile(){
string p...
本文实例讲述了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程序设计有所帮助。