JAVA
1package java11; 2 3import java.io.File; 4import java.io.FileReader; 5import java.io.BufferedReader; 6import java.io.FileNotFoundException; 7import java.io.IOException; 8import java.text.DateFormat; 9 10public class J_11_2 { 11 public static void main (String args[]) throws ParseException { 12 try { 13 File file = new File("//テキストファイル"); 14 if (checkBeforeReadfile(file)) { 15 BufferedReader br = new BufferedReader(new FileReader(file)); 16 String str; 17 while ((str = br.readLine()) != null) { 18 int aindex = str.indexOf("会社名") + "会社名".lenght(); 19 int bindex = str.indexOf("設立日"); 20 if (aindex >=0) { 21 if (bindex >=0) { 22 String kaisha = str.substring(aindex,bindex); 23 System.out.println("会社名" + kaisha); 24 } 25 } 26 int cindex = str.indexOf("代表取締役") + "代表取締役".lenght(); 27 int dindex = str.indexOf("会社名"); 28 if (cindex >=0) { 29 if (dindex >=0) { 30 String daihyou = str.substring(cindex,dindex); 31 System.out.println("代表取締役:" + daihyou); 32 } 33 } 34 int eindex = str.indexOf("設立日") + "設立日:".lenght(); 35 int findex = str.indexOf("資本金"); 36 if (eindex >=0) { 37 if (findex >=0){ 38 String date = str.substring(eindex,findex); 39 Local local = new Local("ja","JP","JP"); 40 DateFormat japaneseFormat = new SimpleDateFormat("GGGGy年M月d日",local); 41 42 Date datestr = japaneseFormat.parse(date); 43 System.out.println("設立日:" + datestr); 44 }
閲覧ありがとうございます。
やりたいことは、
・テキストファイルを読み込ませる。
・1行ずつ読み込んで、指定した行を抽出させ、コンソール画面に出力させる。
・和暦変換。
・会社データクラスを作成。
・2つ以上の関数を使用。
以上の5つです。
出力方法は
会社名:xxxxx
代表取締役:xxxxx
設立日:平成xx年xx月xx日
です。
エラーの原因を調べながら2週間取り組んでいましたが、
正常に起動できませんでした。
もう何をしていいのかわかりません。
ご教授をいただきたいです。
よろしくお願い致します。