如何避免java web start读取资源文件读了多次# Java - 爪哇娇娃
b*i
1 楼
例如:
try {
audioInputStream = AudioSystem.getAudioInputStream(url);//soundFile);
format = audioInputStream.getFormat();
totallength = audioInputStream.getFrameLength()*format.getFrameSize();
waveData = new byte[(int)totallength];
int total=0;
int nBytesRead = 0;
try {
while (nBytesRead != -1 && total nBytesRead = audioInputStream.read(waveData, total, (int)
totallength);
if (nBytesRead>0)
total+=nBytesRead;
}
这样,format,totlalength和.read各自读了一次。如何避免这种情况?
try {
audioInputStream = AudioSystem.getAudioInputStream(url);//soundFile);
format = audioInputStream.getFormat();
totallength = audioInputStream.getFrameLength()*format.getFrameSize();
waveData = new byte[(int)totallength];
int total=0;
int nBytesRead = 0;
try {
while (nBytesRead != -1 && total
totallength);
if (nBytesRead>0)
total+=nBytesRead;
}
这样,format,totlalength和.read各自读了一次。如何避免这种情况?