package in.twizmwaz.cardinal.util; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; public class WebUtils { public static void readURLAndSaveToFile(URL url, File file) { URLConnection urlConnection; try { urlConnection = url.openConnection(); BufferedReader reader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); String line; if (!file.exists()) { file.createNewFile(); } FileWriter fileWriter = new FileWriter(file.getAbsoluteFile()); BufferedWriter writer = new BufferedWriter(fileWriter); while ((line = reader.readLine()) != null) { writer.write(line + "\n"); } writer.close(); reader.close(); } catch (IOException e) { e.printStackTrace(); } } }