Reputation: 7
I need to create 4 output files.
I currently obtain a single file.
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();
Upvotes: 0
Views: 104
Reputation: 1067
You should use different date object to create different file name. Currently you are using a single object which returns the same time each time you call get time().
You can use new Date().get time().
Upvotes: 0
Reputation: 191728
If you want 4 files, then use 4 distinct names.
int i = 0; // Some number counter
for(String url : tableaurl) {
// other code...
i++;
File file = new File(dir + File.separator + i + "_" + date.getTime());
Upvotes: 1