1.从src目录下,读取文本文件内容
public static String inputStreamToString(Class _class, String metadataFileName) throws IOException {
InputStream in = _class.getResourceAsStream(metadataFileName);
StringBuffer out = new StringBuffer();
byte[] b = new byte[4096];
for (int n; (n = in.read(b)) != -1;) {
out.append(new String(b, 0, n));
}
return out.toString();
}
2.从src目录下,读取icon
public static byte[] getIconData(Class clazz, String file) {
try {
InputStream input = clazz.getResourceAsStream(file);
ByteArrayOutputStream output = new ByteArrayOutputStream();
byte[] buffer = new byte[4096];
int n = 0;
while (-1 != (n = input.read(buffer))) {
output.write(buffer, 0, n);
}
return output.toByteArray();
} catch (IOException err) {
err.printStackTrace();
}
return null;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。