Java ReadFileFrom URL
import java.util.Scanner;
public class ReadFileFromURL {
public static void main(String[] args){
System.out.println("Masukan url");
String URLString = new Scanner(System.in).next();
try{
java.net.URL url = new java.net.URL(URLString);
int count = 0;
Scanner input = new Scanner(url.openStream());
while(input.hasNext()){
String line = input.nextLine();
count += line.length();
}
System.out.println("Berapa karakter : " + count);
}catch(java.net.MalformedURLException ex){
System.out.println("Invalid URL");
}catch(java.io.IOException ex){
System.out.println("Error");
}
}
}
Komentar
Posting Komentar