티스토리 뷰

public static void main(String[] args) throws IOException {
  Scanner sc = new Scanner(System.in);
  System.out.println("URL 입력 : ");
  String spec = sc.nextLine();
  System.out.println("저장 할 경로 입력 : ");
  String savePath = sc.nextLine();
  URL url = new URL(spec);
  InputStream is = url.openStream();
  BufferedReader br = new BufferedReader(new InputStreamReader(is,"UTF-8"));
//  BufferedWriter bw = new BufferedWriter(new FileWriter(savePath, true));
  
  //PrintWriter
  PrintWriter pw = new PrintWriter(new BufferedOutputStream(new FileOutputStream(savePath)),true);
  
  String str = null;
  while((str = br.readLine()) != null){
   //println()은 한줄단위로 쓴다.
   pw.println(str);
  }
  is.close();
  br.close();
//  bw.flush();
//  bw.close();
  pw.flush();
  pw.close();
 }

 

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함