Import the Java. IO. *;
Import the Java. Util. HashMap;
Public class P2 {
Public static void main (String [] args) throws IOException {
HashMap
BufferedReader br=new BufferedReader (new FileReader (" paixu. TXT "));
BufferedWriter bw=new BufferedWriter (new FileWriter (" paixu2. TXT "));
String line;
While ((line=br. ReadLine ())!=null) {
//String [] arr=new String [3].
Arr=line. The split (" \ \ ");
//System. Out. Println (arr [0]).
//System. Out. Println (arr [1]).
The map. The put (arr [0], arr [1]).
//System. Out. Println (map);
}
For (String key: map. KeySet ()) {
The String value=https://bbs.csdn.net/topics/map.get (key);
System.out.println(value);
Line=key + "" + value;
Bw. Write (line);
Bw. NewLine ();//write line breaks
}
bw.close();
Br. The close ();
}
}
An Exception in the thread "is the main" Java. Lang. ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1
Line error has been displayed is "map. The put (arr [0], arr [1])," the line
If before the trip plus "System. Out. Println (arr [1]);" , an error is the line
To make the "map. The put (arr [0], arr [1])," commented program running (nothing)
Could you tell me what the problem ah
CodePudding user response:
Only one data only the subscript subscript 0 1 is crossing the lineCodePudding user response:
System. The out. PRNTLN (arr);Arr=line. The split (" \ \ ");
The front print your data, it should be a row no decimal point integral,
CodePudding user response: