import
java.io.BufferedReader;
import java.io. * ;
public class reload ... {
public static void main(String[] args) throws IOException...{?
String s1 = "http://localhost:8080/20051211074416500.mp3";
java.io.InputStream is = null;
java.io.BufferedReader br = null;
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try...{
java.net.URL url = new java.net.URL(s1);
is = url.openStream();
bis = new java.io.BufferedInputStream(is);
}catch(Exception e)...{
System.out.println(e.toString());
}
File file = new File("D:/study/123.mp3");
if(!file.exists())...{
file.createNewFile();
}
try...{
bos = new BufferedOutputStream(new FileOutputStream(file));;
byte[] b = new byte[1024];
int c=0;
while((c=bis.read(b))>0)...{
bos.write(b,0,c);
}
}catch(Exception e)...{
System.out.println(e.toString());
}finally...{
try...{
bos.flush();
bis.close();
}catch(Exception e)...{
System.out.println(e.toString());
}
}
}
}
import java.io. * ;
public class reload ... {
public static void main(String[] args) throws IOException...{?
String s1 = "http://localhost:8080/20051211074416500.mp3";
java.io.InputStream is = null;
java.io.BufferedReader br = null;
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try...{
java.net.URL url = new java.net.URL(s1);
is = url.openStream();
bis = new java.io.BufferedInputStream(is);
}catch(Exception e)...{
System.out.println(e.toString());
}
File file = new File("D:/study/123.mp3");
if(!file.exists())...{
file.createNewFile();
}
try...{
bos = new BufferedOutputStream(new FileOutputStream(file));;
byte[] b = new byte[1024];
int c=0;
while((c=bis.read(b))>0)...{
bos.write(b,0,c);
}
}catch(Exception e)...{
System.out.println(e.toString());
}finally...{
try...{
bos.flush();
bis.close();
}catch(Exception e)...{
System.out.println(e.toString());
}
}
}
}
先把源文件贴出来省得忘了,其实就是个下载文件的问题,关键就是用好JAVA的流,这部分我还要好好看看,回头要详细地写一下。这里有个小误区,就是BufferedOutputStream 得3个方法,我开始的时候就各和BufferedReader弄混了,写了个
while(bis.read(b)!=-1) {
bos.write(b);
留作给自己的警告。
void | flush() Flushes this buffered output stream. |
void | write(byte[] b, int off, int len) Writes len bytes from the specified byte array starting at offset off to this buffered output stream. |
void | write(int b) Writes the specified byte to this buffered output stream. |