Skip to content

Commit

Permalink
Merge pull request #25 from akshatjainei/test102
Browse files Browse the repository at this point in the history
Added support for URL Validation
  • Loading branch information
SaptarshiSarkar12 committed Oct 1, 2022
2 parents 2735ac1 + 6d70df4 commit a1f4304
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/Drifty_CLI.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import java.net.URL;
import java.util.Scanner;

public class Drifty_CLI {
Expand All @@ -24,6 +25,16 @@ public static void main(String[] args) {
while(true) {
System.out.print("Enter the link to the file : ");
String link = SC.next();
while (true) {
if (!validURL(link)) {
System.out.println("Invalid URL. Please enter again");
System.out.print("Enter the link to the file : ");
link = SC.next();
}
else{
break;
}
}
SC.nextLine();
System.out.print("Enter the filename (with file extension) : ");
String fName = SC.nextLine();
Expand Down Expand Up @@ -69,4 +80,14 @@ private static void enterDownloadsFolder(){
downloadsFolder = downloadsFolder + System.getProperty("file.separator");
}
}

private static boolean validURL(String link){
try{
new URL(link).toURI();
return true;
}
catch (Exception e){
return false;
}
}
}

0 comments on commit a1f4304

Please sign in to comment.