1. From the SRC directory, read the contents of the text file
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. From the SRC directory, read 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))) {
&NBS P output.write (buffer, 0, N);
}
return Output.tobytearray ();
} catch (IOException err) {
Err.printstacktra CE ();
}
return null;
}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Android reads the file under SRC