for(int j = 0 ; j
if (!fu.isFileExist("TB/"+Titlename[i]+"/"+j+".jpg"))
{
myDownFile.downFile(Pathname[j], "TB/"+Titlename[i]+"/", j+".jpg");
}
}
这一段我循环下载Pathname这个数组里面是指针,这个类是写的,主要代码如
public int downFile(String urlStr,String path,String fileName)
{
Log.i("通知:", "downFilebegin");
InputStream in = null;
FileUtils fu = new FileUtils();
try
{in = getInputStreamFromUrl(urlStr);
Log.i("通知:","writer2SDFromIinput-bigen");
File resultFile = fu.writer2SDFromIinput(path, fileName, in);
Log.i("通知:","writer2SDFromIinput-end");
if (resultFile == null)
{
return -1;
}
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{
try
{
in.close();
}
catch(Exception e)
{
e.printStackTrace();
return -1;
}
}
return 0;
}
public InputStream getInputStreamFromUrl(String urlStr) throws IOException
{
URL url = new URL(urlStr);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setConnectTimeout(5*1000);
connection.setRequestMethod("GET");
System.getProperties().put( "proxySet", "true" );
System.getProperties().put( "proxyHost", "192.168.0.107" );
System.getProperties().put( "proxyPort", "8080");
InputStream inputStream = connection.getInputStream();
return inputStream;
}
其中File 类是写的,主要代码如下
public File writer2SDFromIinput(String path, String fileName, InputStream input)
{
File file = null;
OutputStream output = null;
try
{
// 创建目录 dir.mkdir();
createSDDir(path);
file = createSDFile(path+fileName);
output = new FileOutputStream(file);
byte buffer[] = new byte[4 * 1024];
while ((input.read(buffer)) != -1)
{
output.write(buffer);
}
output.flush();
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
try
{
output.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
return file;
}
但是下载下来的图片很多都是花了的。。求高手指点迷津