【Java】ログインデータ管理プログラム【csv】

import java.io.File;
import java.io.FileWriter;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.*;
import java.util.List;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.LinkedList;
class ConsoleLoginEntry{
  public static final String csLoginRootPath = "";
  public static final String csLoginFilePath = "LoginData.csv";
  public static void main(String args[]){
    File ofLogin = new File(csLoginRootPath + csLoginFilePath);
    if (ofLogin.exists()){
      //System.out.println("ファイルは存在します");
    }else{
      System.out.println("ファイルが存在しません");
      System.out.println("ファイルを作成しますか?(Y)");
      try{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String sYesNo = br.readLine();
        if(sYesNo.equals("Y")){
          if(!ofLogin.createNewFile()){
            System.out.println("ファイルを作成できませんでした 終了します");
            return;
          }
        }else{
          System.out.println("終了します");
          return;
        }
      }catch(IOException e){
        System.out.println("Exception :" + e);
      }
    }
    String sID = "";
    String sPassWord = "";
    boolean bId = false;
    //IDの入力検査
    try{
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      System.out.print("IDを入力してください   ⇒  ");
      sID = br.readLine();
      sID = sID.trim();
      if(sID.equals("")){
        System.out.println("IDが入力されませんでした 終了します");
        return;
      }
      if(sID.indexOf(',') > -1){
        System.out.println("IDに','(カンマ)文字を使う事はできません");
        return;
      }
    }catch(IOException e){
      System.out.println("Exception :" + e);
    }
    
    //ログイン情報ファイル
    if (ofLogin.exists()){
      try{
        BufferedReader brFile = new BufferedReader(new FileReader(ofLogin));
        List<String[]> csv = new ArrayList<String[]>();
        String str = brFile.readLine();
        while (str != null) {
          csv.add(str.split(","));
          str = brFile.readLine();
        }
        brFile.close();
        bingo:
        for(String[] line : csv) {
          String s[] = line[0].split(",");          
          if (sID.equals(s[0])){
            bId = true;
            break bingo;
          }
        }
      }catch(IOException e){
        System.out.println("Exception :" + e);
      }
      //パスワードの変更可否
      if (bId){
        System.out.println("そのIDは既に存在します");
        System.out.println("PassWordを変更しますか?(Y) IDを削除しますか?(D)");
        try{
          BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
          String sYesNoDelete = br.readLine();
          //パスワードのみ変更
          if(sYesNoDelete.equals("Y")){
            System.out.println("パスワードを入力して下さい");
            BufferedReader br2 = new BufferedReader(new InputStreamReader(System.in));
            String sChangePassWord = br2.readLine();
            sChangePassWord = sChangePassWord.trim();
            if(sChangePassWord.equals("")){
              System.out.println("PassWordが入力されませんでした 終了します");
              return;
            }
            if(sChangePassWord.indexOf(',') > -1){
              System.out.println("PassWordに','(カンマ)文字を使う事はできません 終了します");
              return;
            }
            System.out.println("ID=" + sID + " PassWord=" + sChangePassWord);
            //変更前ログインデータを取得
            try{
              BufferedReader brFile = new BufferedReader(new FileReader(ofLogin));
              List<String[]> csv = new ArrayList<String[]>();
              String str = brFile.readLine();
              while (str != null) {
                csv.add(str.split(","));
                str = brFile.readLine();
              }
              brFile.close();
              //変更するログインデータ作成
              LinkedList<String> Newlist = new LinkedList<String>();
              for(String[] line : csv) {
                String s[] = line[0].split(",");          
                if (sID.equals(s[0])){
                  Newlist.add(sID + "," + sChangePassWord);
                }else{
                  Newlist.add(line[0] + "," + line[1]);
                }
              }
              //変更ログインデータファイル作成
              try{
                File Tempfile = new File(csLoginRootPath + "Temp.csv");
                FileWriter filewriter = new FileWriter(Tempfile);
                for (int i = 0; i < Newlist.size(); i++) {
                  filewriter.write(Newlist.get(i) + "\r\n");
                }
                filewriter.close();
                //リネームして正規ログインデータファイルにする
                ofLogin.delete();
                File fNew = new File(csLoginFilePath);
                Tempfile.renameTo(fNew);
              }catch(IOException e){
                System.out.println(e);
              }
              for (int i = 0; i < Newlist.size(); i++) {
                System.out.println(Newlist.get(i));
              }      
              System.out.println("パスワードは変更されました 終了します");
            }catch(IOException e){
              System.out.println("Exception :" + e);
            }
            return;
          //IDごと削除する
          }else if(sYesNoDelete.equals("D")){
            try{
              BufferedReader brFile = new BufferedReader(new FileReader(ofLogin));
              List<String[]> csv = new ArrayList<String[]>();
              String str = brFile.readLine();
              while (str != null) {
                csv.add(str.split(","));
                str = brFile.readLine();
              }
              brFile.close();
              //変更するログインデータ作成
              LinkedList<String> Newlist = new LinkedList<String>();
              for(String[] line : csv) {
                String s[] = line[0].split(",");          
                if (sID.equals(s[0])){
                  //Newlist.add(sID + "," + sChangePassWord);
                }else{
                  Newlist.add(line[0] + "," + line[1]);
                }
              }
              //変更ログインデータファイル作成
              try{
                File Tempfile = new File(csLoginRootPath + "Temp.csv");
                FileWriter filewriter = new FileWriter(Tempfile);
                for (int i = 0; i < Newlist.size(); i++) {
                  filewriter.write(Newlist.get(i) + "\r\n");
                }
                filewriter.close();
                //リネームして正規ログインデータファイルにする
                ofLogin.delete();
                File fNew = new File(csLoginFilePath);
                Tempfile.renameTo(fNew);
              }catch(IOException e){
                System.out.println(e);
              }
              //ログインデータ一覧を表示(確認用)
              /*
              for (int i = 0; i < Newlist.size(); i++) {
                System.out.println(Newlist.get(i));
              }
              */      
              System.out.println("正常に削除されました 終了します");
            }catch(IOException e){
              System.out.println("Exception :" + e);
            }
            return;
          }else{
            System.out.println("終了します");
          }
        }catch(IOException e){
          System.out.println("Exception :" + e);
        }
        return;
      }
    }
    //新規IDのパスワードの入力検査
    try{
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      System.out.print("PassWordを入力してください   ⇒  ");
      sPassWord = br.readLine();
      sPassWord = sPassWord.trim();
      if(sPassWord.equals("")){
        System.out.println("PassWordが入力されませんでした 終了します");
        return;
      }
      if(sPassWord.indexOf(',') > -1){
        System.out.println("PassWordに','(カンマ)文字を使う事はできません 終了します");
        return;
      }
    }catch(IOException e){
      System.out.println("Exception :" + e);
    }
    //新規IDと新規パスワードを登録
    try{
      File file = new File(csLoginRootPath + csLoginFilePath);
      FileWriter filewriter = new FileWriter(file, true);
      filewriter.write(sID + ',' + sPassWord + "\r\n");
      filewriter.close();
      System.out.println("登録は完了しました 終了します");
    }catch(IOException e){
      System.out.println(e);
    }
  }
}