我需要創建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