?? listing15-07_resourcereader.java_ok
字號(hào):
// Listing 15-7. Reading a Resource Correctly Using Some Defensive Techniques
public class ResourceReader {
public byte[] readResource( String url )
throws IOException
{
InputStream in = getClass().getResourceAsStream( url );
byte[] buffer;
// the following always returns 0 on Symbian and Motorola:
int available = in.available();
if ( available == 0 ) {
available = 4 * 1024; // 4 kb
}
buffer = new byte[ available ];
ByteArrayOutputStream out = new ByteArrayOutputStream( available );
int read;
try {
while ( (read = in.read( buffer ) ) != -1 ) {
out.write( buffer, 0, read );
}
} finally {
in.close();
}
return out.toByteArray();
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -