お世話になっています。
わからない箇所があり、質問させて頂きます。
javaでcsvファイルを読み込み、そのファイルが存在しない時、ファイルのフォーマットが不正の時、ファイルの中身が空の時にエラーを発生させたいのですが、ファイルの中身が空の時だけエラーを発生させることができずにいます。
どこの書き方がおかしいのか
ご教授お願い致します。
以下ソース
public class Earning{
private static final String BRANCH = "branch.lst"; public static void main(String[] args) throws SQLException, IOException, ClassNotFoundException { String line = ""; BufferedReader br = null; String dir = (args[0]); dir = dir + "\\"; File branchFile = new File(dir + BRANCH); if (!branchFile.exists()) { System.out.println("ファイルが存在しません"); return; } ArrayList<HashMap<String, String>> branchs = new ArrayList<HashMap<String, String>>(); try { br = new BufferedReader(new FileReader(branchFile)); while ((line = br.readLine()) != null) { String[] datas = line.split(","); if (br.equals(null)){ System.out.println("ファイルの中身が空です"); return; } if (!datas[0].matches("^[0-9]{3}$") || datas.length != 2) { System.out.println("ファイルフォーマットが不正です"); return; } HashMap<String,String>map = new HashMap<String, String>(); map.put("branchCode", datas[0]); map.put("branchName", datas[1]); branchs.add(map); } } catch (IOException e) { e.printStackTrace(); return; } finally { try { br.close(); } catch (Exception e) { } }

回答4件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/01/07 08:14