-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path45 .File Class.java
More file actions
59 lines (48 loc) · 1.3 KB
/
45 .File Class.java
File metadata and controls
59 lines (48 loc) · 1.3 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package test;
import java.util.Arrays;
import java.util.Scanner;
//import javax.swing.*;
//import java.lang.Math;
//import java.util.Random;
//import java.awt.Color; // abstract window toolkit
import java.io.IOException;
//import java.util.Arrays;
//import java.util.ArrayList;
//import java.util.List;
//import java.util.Map;
//import java.util.HashMap;
import java.io.File;
import java.util.*;
public class main {
// File Class .
// File Class :
//
public static void main(String[] args) {
// TODO Auto-generated method stub
// Declare the Scanner library
Scanner scanner = new Scanner(System.in);
// Static Declaration
File file = new File("ia.txt");
// Creating a file
try {
if (file.createNewFile()) {
System.out.println("File has been created successfully!");
}
}catch (Exception e) {
System.out.println("Error occurred while creating the file : " + e);
}
// checking a file
if (file.exists()) {
System.out.println("File exists!");
}else {
System.out.println("File does not exists!");
}
// Getting the absolute path of a file
String path_str = file.getAbsolutePath();
System.out.println("Absolute Path : " + path_str);
// Deleting a file
if(file.delete()) {
System.out.println("the file deleted successfully");
}
}
}