Advertisement
Raizekas

Untitled

Mar 26th, 2017
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.42 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package auto_database;
  7. import java.net.*;
  8. import java.io.*;
  9.  
  10. public class Auto_database {
  11.     public static void main(String[] args) {
  12.  
  13.         URL carUrl;            // car's URL
  14.         try {
  15.             // get URL
  16.             carUrl = new URL("http://www.auto24.ee/used/2435664");
  17.             URLConnection carConn = carUrl.openConnection();
  18.  
  19.             // open the stream
  20.             BufferedReader br = new BufferedReader(new InputStreamReader(carConn.getInputStream()));
  21.  
  22.             String inputLine;
  23.  
  24.             String fileName = "sourceFile.txt";
  25.             File file = new File(fileName);
  26.  
  27.             if (!file.exists())
  28.                 file.createNewFile();
  29.  
  30.             FileWriter fw = new FileWriter(file.getAbsoluteFile());
  31.             BufferedWriter bw = new BufferedWriter(fw);
  32.  
  33.             while ((inputLine = br.readLine()) != null)
  34.             {
  35.                 bw.write(inputLine);
  36.                 bw.write("\n");
  37.             }
  38.  
  39.             bw.close();
  40.             br.close();
  41.  
  42.             System.out.println("Bravisimo");
  43.     }
  44.         catch (MalformedURLException e) {
  45.             e.printStackTrace();
  46.         }
  47.         catch (IOException e) {
  48.             e.printStackTrace();
  49.         }
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement