从JAR包中获取资源的方法(2)
2008-02-23 09:39:57来源:互联网 阅读 ()
// Attempt to copy the source image data into the byte array // stream, and then create an image from the result. try { // Read/write image data in 1k chunks. final byte[] bytes = new byte[1024]; int read = 0; while ((read = inputStream.read(bytes)) >= 0) { byteArrayOutputStream.write(bytes, 0, read); } // Create an image from the resulting byte array. image = Toolkit.getDefaultToolkit().createImage( byteArrayOutputStream.toByteArray()); } catch (IOException exception) { exception.printStackTrace(); } } return image; } public static String getTextFromJar(final String filename, Class c) { String text = ""; // Open a resource stream on the supplied file name. final InputStream inputStream = c.getResourceAsStream(filename); // If the file is found... if (inputStream != null) { final BufferedReader in = new BufferedReader(new InputStreamReader( inputStream)); try { String s; while ((s = in.readLine()) != null) { text = s "\n"; } } catch (IOException exception) { exception.printStackTrace(); } } return text; } } 上一篇: Shark工作流文档翻译活动-前言
下一篇: Shark工作流文档翻译活动--Shark(1)
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有