我正在使用Java
, aReadableByteChannel
并FileOutputStream
尝试从 Soundcloud 中提取一个 wav 文件:
public static void wavTest() {
URL website = null;
try {
website = new URL("https://api.soundcloud.com/tracks/123456789/download?client_id=12lhfdh5k55....283);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ReadableByteChannel rbc = null;
try {
rbc = Channels.newChannel(website.openStream());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
FileOutputStream fos = null;
try {
fos = new FileOutputStream("/Users/name/Desktop/test.wav");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
该 URL 在粘贴到浏览器并下载完整曲目时有效,但无论我尝试使用上面的代码下载哪些曲目,该文件始终具有以下属性:
28 bytes (4 KB on disk)
显然我做错了什么。任何人都可以帮助我或指出我正确的方向吗?