先生,我是Java新手,我想在URL路径上写文件是否有任何可能的方法在URL路径上写文件给我一些提示
不,您不能将URL路径和FileName都作为参数传递给FileOutputStream。
但是,您可以使用以下代码通过读取指定的URL将a写入文件:
try{
URL url = new URL("http://docs.oracle.com/javase/7/docs/api/java/io/FileOutputStream.html");
String path = "D://StackOverflow/";
InputStream ins = url.openStream();
OutputStream ous = new FileOutputStream(path);
final byte[] b = new byte[2048];
int length;
while ((length = ins.read(b)) != -1) {
ous.write(b, 0, length);
}
ins.close();
ous.close();
} catch(Exception e){
e.printStackTrace();
}
能否请您解释一下通过将URL和fileName传递给FileOutPutStream来实际实现的目标?
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句