我需要创建4个输出文件。从字符串数组创建输出文件
我目前获得一个文件。
String url1 = "www.xxxx.com";
String url2 = "www.xxxx.com";
String url3 = "www.xxxx.com";
String url4 = "www.xxxx.com";
String tableaurl[] = {url1,url2,url3,url4};
for(String url : tableaurl)
{
String encodedString = UrlUtils.encodeAnchor(url);
System.out.format("%s\n", encodedString);
URL myURL = new URL(encodedString);
String userpass = "username" + ":" + "password";
String basicAuth = "Basic " + Base64.encode(userpass.getBytes("UTF-8"));
URLConnection myURLConnection = myURL.openConnection(proxy);
myURLConnection.setRequestProperty("Authorization", basicAuth);
myURLConnection.connect();
InputStream is = myURLConnection.getInputStream();
BufferedReader br = null;
File dir = new File(home + File.separator + "collected" + File.separator +"test");
dir.mkdirs();
File file = new File(dir + File.separator + date.getTime());
FileOutputStream fos = new FileOutputStream(file);
StringBuilder sb = new StringBuilder();
此代码应该已经创建了4个文件,标记为'new File(dir + File.separator + date.getTime());'(假设时间不同) –
hello cricket_007,谢谢。 – baba
这是代码的结尾:String line; \t \t \t \t尝试{ \t \t \t \t \t \t \t \t \t \t INT读= 0; \t \t \t \t \t byte [] bytes = new byte [1024]; \t \t \t \t \t而((读取= is.read(字节))= - 1!){ \t \t \t \t \t \t fos.write(字节,0,读); \t \t \t \t \t \t // sb.append(line); \t \t \t \t \t} \t \t \t \t}赶上(例外五){ \t \t \t \t \t e.printStackTrace(); \t \t \t \t \t \t \t \t \t} – baba