new files
This commit is contained in:
parent
3af7344581
commit
86c034bb8b
1364 changed files with 21352 additions and 0 deletions
|
|
@ -0,0 +1,18 @@
|
|||
import java.io.File;
|
||||
public class FileExistsTest {
|
||||
public static boolean isFileExists(String filename) {
|
||||
boolean exists = new File(filename).exists();
|
||||
return exists;
|
||||
}
|
||||
public static void test(String type, String filename) {
|
||||
System.out.println("The following " + type + " called " + filename +
|
||||
(isFileExists(filename) ? " exists." : " not exists.")
|
||||
);
|
||||
}
|
||||
public static void main(String args[]) {
|
||||
test("file", "input.txt");
|
||||
test("file", File.separator + "input.txt");
|
||||
test("directory", "docs");
|
||||
test("directory", File.separator + "docs" + File.separator);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
import java.nio.file.FileSystem;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Files;
|
||||
public class FileExistsTest{
|
||||
private static FileSystem defaultFS = FileSystems.getDefault();
|
||||
public static boolean isFileExists(String filename){
|
||||
return Files.exists(defaultFS.getPath(filename));
|
||||
}
|
||||
public static void test(String type, String filename){
|
||||
System.out.println("The following " + type + " called " + filename +
|
||||
(isFileExists(filename) ? " exists." : " not exists.")
|
||||
);
|
||||
}
|
||||
public static void main(String args[]){
|
||||
test("file", "input.txt");
|
||||
test("file", defaultFS.getSeparator() + "input.txt");
|
||||
test("directory", "docs");
|
||||
test("directory", defaultFS.getSeparator() + "docs" + defaultFS.getSeparator());
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue