package edu;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Scanner;
public class Rei23 {
public void Rei()throws IOException{
boolean F=true;
// File a=new File("C:\\R03kensyu\\TOKMS.DAT");
while (F) {
ArrayList<String>list =new ArrayList<String>();
System.out.println("処理区分 (1:追加 2:削除 3:参照 4:終了)");
BufferedReader Br = new BufferedReader(new InputStreamReader(System.in));
File A=new File("C:\\R03kensyu\\INDEX.DAT");
//操作人の最初の数字をBに保存 Br
String b=Br.readLine();
int B=Integer.parseInt(b);
System.out.println("処理指令をわかりました");
switch(B) {
case 1:{
System.out.println("得意コードを入力して下さい");
String filePar="C:\\R03kensyu";
String filename="TOKMS.DAT";
//2つのファイルを開けて、fw,fw1
FileWriter fw=new FileWriter("C:\\R03kensyu\\TOKMS.DAT",true);
FileWriter fw1=new FileWriter("C:\\R03kensyu\\INDEX1.DAT",true);
String str=Br.readLine();
int temp=Integer.parseInt(str);
int contindex=0;int t=0; String c="1";
String str1=Br.readLine();
if (t==5)System.out.println("限外です");
while(temp!=999&&t<=4){
fw.write(str);
fw.write(",");
fw.write(str1+"\n");
System.out.println("入力成功");
if(contindex<=24) {
contindex++;
fw1.write(c);
fw1.write("A");
fw1.write(",");
int i = Integer.parseInt(c);
i++;
c=Integer.toString(i);
}
if(contindex==25) {
fw1.write("\n");
fw1.write(c);
fw1.write("A");
//fw1.write(",");
int i = Integer.parseInt(c);
i++;
c=Integer.toString(i);
contindex=0;
t=t+1;
}
str=Br.readLine();
temp=Integer.parseInt(str);
str1=Br.readLine();
}
System.out.println("追加を完了しました.処理指令を入力して下さい");
fw1.close();
fw.close();
break;
}
case 2:{
System.out.println("得意コードを入力して下さい");
//得意数字放在temp中
File a=new File("C:\\R03kensyu\\TOKMS.DAT");
Scanner scan = new Scanner(a).useDelimiter(",");
FileWriter fw=new FileWriter("C:\\R03kensyu\\TOKMS.DAT",true);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//操作人の最初の数字をBに保存
String w=br.readLine();
//scanner に保存したの数字をannalist に保存
//キーボードから入力した数字をwに保存
int W=Integer.parseInt(w);
String str=scan.next();
int Temp=Integer.parseInt(str);
ArrayList<Integer> li=new ArrayList<>();
ArrayList<Integer> li1=new ArrayList<>();
String strtemp;
int count[]=null;
int mark=1;
int Count=0;
while(scan.hasNext())
{ //重复读取文件中的数字直到结束
if(W==Temp) {
li.add(Temp);
//把相同数字出现的位置记录,记录在list1中,list1中的值就是相同数字出现的位置,大于25除以25
li1.add(mark);
mark++;
strtemp= scan.nextLine();
str=scan.next();
Temp=Integer.parseInt(str);
Count=1;
}
if(W!=Temp){
li.add(Temp);
strtemp=scan.nextLine();
if(scan.hasNext()) {
str=scan.next();
Temp=Integer.parseInt(str);
mark++;}
else break;
}
}
if(Count==0) {
System.out.println("該当なし");}
for(int j=0;j<li.size();j++){
System.out.println("list中每个值为"+li.get(j)+"");}
for(int k=0;k<li1.size();k++){
System.out.println("list1中每个值为"+li1.get(k)+"");
}
fw.close();
br.close();
scan.close();
FileWriter fw1=new FileWriter("C:\\R03kensyu\\INDEX1.DAT",true);
int contindex=0;boolean m=true;
while (m=true) {
String c="1";int t=1;
fw1.write("\n");
for(int j=0;j<li1.size();j++){
if(contindex<=24) {
if(li1.get(j)==Integer.parseInt(c)) {
contindex++;
fw1.write(c);
fw1.write("D");
fw1.write(",");
int i = Integer.parseInt(c);
i++;
c=Integer.toString(i);}
else {
contindex++;
fw1.write(c);
fw1.write("A");
fw1.write(",");
int i = Integer.parseInt(c);
i++;
c=Integer.toString(i);
}
}
if(contindex==25) {
fw1.write("\n");
fw1.write(c);
fw1.write("A");
}
}
m= false;}
}
/*case 3:{
System.out.println("得意コードを入力して下さい");
String str=Br.readLine();
int temp=Integer.parseInt(str);
BufferedReader brf = null;
brf = new BufferedReader(new FileReader("C:\\R03kensyu\\INDEX.DAT"));
System.out.println("开始读文件 ");
String c=brf.readLine();
while
while((temp!=999)) {
//開始で入力したそ得意数字とtemp一致しているが、一致なら出力
if(B==Temp) {
t=1;
str=scan.nextLine();
String c[]=str.split(",",2);
for (int i = 1; i < c.length; i++){
System.out.println(" 対応の文章は"+c[i]);
}
//次のはファイルの後ろがどうか判断する、じゃない場合は後ろにいく
if(scan.hasNextLine()){
str=scan.next();
Temp=Integer.parseInt(str);
}
//合ってる場合はファイルを初期化
else
{
scan.reset();
scan = new Scanner(a).useDelimiter(",");
System.out.println("ファイルの全部搜索完成、他の数字を入力してください");
b=br.readLine();
B=Integer.parseInt(b);
str=scan.next();
Temp=Integer.parseInt(str);
}
}
//先ず入力したの得意先数字を判断する、とtemp一致しているが、一致しないならファイルの終了ではない場合
else if((B!=Temp)&&(scan.hasNextLine())){
str=scan.nextLine();
str=null;
if(scan.hasNextLine())
{String str1=scan.next();
Temp=Integer.parseInt(str1);
}
else
{scan.reset();
scan = new Scanner(a).useDelimiter(",");
System.out.println("ファイルの全部搜索完成,他の数字を入力してください");
b=br.readLine();
B=Integer.parseInt(b);
str=scan.next();
Temp=Integer.parseInt(str);
}
}
else if(B!=Temp){
System.out.println("ファイルの全部搜索完成,見つからない");
scan.reset();
scan = new Scanner(a).useDelimiter(",");
b=br.readLine();
B=Integer.parseInt(b);
}
}
}*/
case 4:{
F=false;
System.out.println("処理を完了しました,終了です");
break;
}
}
if( F!=false)
System.out.println("処理を完了しました,次の命令を入力してください");
else
System.out.println("終了です");
}
}
}