package FileHandling;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
public class BufferedFile {
public static void main(String[] args) throws IOException {
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Please enter the file name to create :");
String file_name=in.readLine();
File file=new File(file_name);
boolean exists=file.createNewFile();
if(!exists)
{
System.out.println("File already exists");
System.exit(0);
}
else
{
FileWriter fi=new FileWriter(file_name);
BufferedWriter out=new BufferedWriter(fi);
System.out.println("Enter charaters to be written in file ");
out.write(in.readLine());
out.close();
System.out.println("File created successfully");
}
}
}
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
public class BufferedFile {
public static void main(String[] args) throws IOException {
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Please enter the file name to create :");
String file_name=in.readLine();
File file=new File(file_name);
boolean exists=file.createNewFile();
if(!exists)
{
System.out.println("File already exists");
System.exit(0);
}
else
{
FileWriter fi=new FileWriter(file_name);
BufferedWriter out=new BufferedWriter(fi);
System.out.println("Enter charaters to be written in file ");
out.write(in.readLine());
out.close();
System.out.println("File created successfully");
}
}
}
After running this program the file named you in output is created here abhi is the file which is created after running the program
0 comments:
Post a Comment