-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFileDemo.java
More file actions
47 lines (39 loc) · 1.17 KB
/
Copy pathFileDemo.java
File metadata and controls
47 lines (39 loc) · 1.17 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
package com.sample;
import java.io.*;
import java.util.*;
import javax.imageio.stream.FileImageInputStream;
public class FileDemo {
@SuppressWarnings({ "resource" })
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
Scanner sc= new Scanner(System.in);
Date d= new Date();
File file= new File("C:\\Users\\ABBURI'S\\Documents\\newfile.txt");
if(!file.exists())
{
file.createNewFile();
System.out.println("File created");
}
else
{
System.out.println("file already exists");
}
//FileInputStream fis=new FileInputStream(file);
BufferedWriter bw=new BufferedWriter(new FileWriter(file,true));
bw.write(d.toString());
System.out.println("Enter text:");
//bw.newLine();
//bw.write(d.toString());
bw.newLine();
bw.write(sc.next());
bw.close();
//FileReader fr=new FileReader(file);
BufferedReader br= new BufferedReader(new FileReader(file));
String in=null;
//System.out.println(d.toString());
while((in = br.readLine()) != null)
{
System.out.println(in);
}
}
}