Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.FileWriter;
- import java.io.Writer;
- import java.net.URL;
- import java.util.Scanner;
- public class A {
- public static void main(String[] args) {
- if (args.length < 2) System.exit(1);
- URL url = null;
- try {
- url = new URL(args[0]);
- }
- catch (Exception e) {
- System.err.println("url error.");
- System.exit(1);
- }
- Scanner in = null;
- try {
- in = new Scanner(url.openStream());
- }
- catch (Exception e) {
- System.err.println("url can't open.");
- System.exit(1);
- }
- Writer out = null;
- try {
- out = new FileWriter(args[1]);
- }
- catch (Exception e) {
- System.err.println("write file error.");
- System.exit(1);
- }
- StringBuffer sb = new StringBuffer();
- while (in.hasNextLine()) {
- sb.append(in.nextLine());
- sb.append('\n');
- }
- try {
- out.write(sb.toString());
- }
- catch (Exception e) {
- System.err.println("write error.");
- System.exit(1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement