-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFillePath.java
42 lines (35 loc) · 986 Bytes
/
FillePath.java
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
32
33
34
35
36
37
38
39
40
41
42
package com.javamultiplex.filehandling;
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
public class FillePath {
public static void main(String[] args) throws IOException {
Scanner input = null;
try {
input = new Scanner(System.in);
System.out.println("Enter file name with extension : ");
String filename = input.nextLine();
if (isValidFileName(filename)) {
String workingDirectory = System.getProperty("user.dir");
String absoluteFilePath = workingDirectory + File.separator + filename;
System.out.println("File path : "+absoluteFilePath);
}
else
{
System.out.println("File name is not valid.");
}
} finally {
if (input != null) {
input.close();
}
}
}
private static boolean isValidFileName(String fileName) {
String pattern = "^.+\\..+$";
boolean result = false;
if (fileName.matches(pattern)) {
result = true;
}
return result;
}
}