If you want an AudioInputStream
, you can load the entire file in to a byte array:
static AudioInputStream load(File file) throws IOException {
try (FileInputStream in = new FileInputStream(file)) {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
byte[] buf = new byte[4096];
for (int b; (b = in.read(buf)) > -1;) {
bytes.write(buf, 0, b);
}
return AudioSystem.getAudioInputStream(
new ByteArrayInputStream(bytes.toByteArray());
}
}
Or in Java 7:
static AudioInputStream load(File file) throws IOException {
return AudioSystem.getAudioInputStream(
new ByteArrayInputStream(Files.readAllBytes(file.toPath()));
}