Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.BufferedReader;
- import java.io.OutputStreamWriter;
- import java.util.Scanner;
- import java.io.BufferedWriter;
- public class Main {
- static BufferedReader input;
- static BufferedWriter output;
- public static void main(String[] args ) {
- try {
- File f = new File("student.txt");
- FileInputStream fis = new FileInputStream(f);
- InputStreamReader isr = new InputStreamReader(fis);
- input = new BufferedReader(isr);
- char choice = 'R' ;
- boolean access = false;
- File file2 = new File("student2.txt");
- if(file2.exists()) {
- System.out.println("The File Already Exists in The Directory , Please Enter A To Append or R to rewrite");
- choice = (char)System.in.read();
- }
- access = (choice == 'A')?true:false;
- System.out.println(choice);
- System.out.println(access);
- FileOutputStream fos = new FileOutputStream(file2,access);
- OutputStreamWriter osw = new OutputStreamWriter(fos);
- output = new BufferedWriter(osw);
- while(input.ready()) {
- String s = input.readLine();
- String [] lines = s.split(",");
- for (int i = 0; i < lines.length; i++) {
- output.write(lines[i]);
- output.newLine();
- }
- }
- }
- catch(IOException e) {
- System.out.println(e);
- }
- finally {
- try {
- input.close();
- output.close();
- }
- catch(IOException e) {
- System.out.println(e);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement