-
Notifications
You must be signed in to change notification settings - Fork 0
/
Filehand.java
50 lines (45 loc) · 1.69 KB
/
Filehand.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
43
44
45
46
47
48
49
50
import java.io.*;
import java.io.FileWriter;
import java.util.*;
public class Filehand{
public static void main(String[] args) {
try{
File f=new File("C:\\Users\\lasta\\Desktop\\java\\hello1.txt");
boolean var=f.createNewFile();
if(var){
System.out.println("new file has been created");
}
else{
System.out.println("no file created");
}
FileWriter f1=new FileWriter("hello1.txt");
f1.write("Files in Java are seriously good!! lorem");
f1.close();
Writer f2=new FileWriter("hello1.txt",false); //overwriting the text
f2.write("hello there guys");
f2.close();
if(f.exists()){
System.out.println("File name :"+f.getName());
System.out.println("File path :"+f.getAbsolutePath());
System.out.println("File writable :"+f.canWrite());
System.out.println("File length :"+f.length());
}
Scanner reader=new Scanner(f);
while(reader.hasNextLine()){
String Fc=reader.nextLine();
System.out.println(Fc);
int vowels=0;
for(int i=0;i<Fc.length();i++){
if(Fc.charAt(i)=='o'){
vowels++;
}
}
System.out.println("Number of I in the file : "+vowels);
reader.close();
}
}
catch(Exception e){
System.out.println(e);
}
}
}