|
![]() |
名片设计 CorelDRAW Illustrator AuotoCAD Painter 其他软件 Photoshop Fireworks Flash |
|
public static String loadAFileToStringDE1(File f) throws IOException { long beginTime = System.currentTimeMillis(); InputStream is = null; String ret = null; try { is = new BufferedInputStream( new FileInputStream(f) ); long contentLength = f.length(); ByteArrayOutputStream outstream = new ByteArrayOutputStream( contentLength > 0 ? (int) contentLength : 1024); byte[] buffer = new byte[4096]; int len; while ((len = is.read(buffer)) > 0) { outstream.write(buffer, 0, len); } outstream.close(); ret = outstream.toString(); //byte[] ba = outstream.toByteArray(); //ret = new String(ba); } finally { if(is!=null) {try{is.close();} catch(Exception e){} } } long endTime = System.currentTimeMillis(); System.out.println(\"方式1用时\"+ (endTime-beginTime) + \"ms\"); return ret; } public static String loadAFileToStringDE2(File f) throws IOException {
public static String loadAFileToStringDE3(File f) throws IOException { 3个方式去读取一个大于50M的文件,当不设置jvm参数时都OutofMemery,当设置-Xmx128M时。只有方式3 可以通过,设置到-Xmx256M时也只有方式3可以通过,干脆设置512M,都可以了,运行时间假如正常的话一般都在4~5S 返回类别: 教程 上一教程: 用java学习数据结构--单链表 下一教程: 取时间的小类 您可以阅读与"java io读取文件到String"相关的教程: · 从JAVA档案(JAR)中读取文件 · JAVA:配置文件读取器 · JAVA读取配置文件例子 · java连接oracle,取io文件内容,子串替换 · 通过java提供的URL类包读取网上的文件 |
![]() ![]() |
快精灵印艺坊 版权所有 |
首页![]() ![]() ![]() ![]() ![]() ![]() ![]() |