Skip to content

Commit 165820f

Browse files
Add files via upload
1 parent 5e79c4b commit 165820f

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

File-Writer/filewriter.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import java.io.File;
2+
import java.io.FileWriter;
3+
import java.io.IOException;
4+
import java.util.Scanner;
5+
6+
public class filewriter {
7+
public static void main(String[] args) {
8+
Scanner scn = new Scanner(System.in);
9+
System.out.println("Enter File name to Write on.");
10+
System.out.print("File Name Here : ");
11+
String filesn = scn.next();
12+
System.out.println("Enter what you need add here : ");
13+
String writen = scn.next();
14+
try {
15+
FileWriter writer = new FileWriter(filesn + ".txt");
16+
writer.write(writen);
17+
writer.close();
18+
System.out.println("Successfully wrote to the file");
19+
} catch (IOException e) {
20+
System.out.println("An Error Occurred");
21+
e.printStackTrace();
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)