
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class Final {
public static void main(String[] args) throws IOException {
int[][] chessArray1 = new int[11][11];
chessArray1[1][2]=1;
chessArray1[2][3]=2;
chessArray1[3][4]=1;
chessArray1[4][5]=2;
int sum=0;
for(int i=0;i<chessArray1.length;i++){
for(int j=0;j<chessArray1[0].length;j++){
if(chessArray1[i][j]!=0) sum++;
}
}
int[][] sparseArray = new int[sum+1][3];
sparseArray[0][0]=11;
sparseArray[0][1]=11;
sparseArray[0][2]=sum;
int temp=1;
for(int i=0;i<chessArray1.length;i++){
for(int j=0;j<chessArray1[0].length;j++){
if(chessArray1[i][j]!=0){
sparseArray[temp][0] =i;
sparseArray[temp][1] =j;
sparseArray[temp++][2] =chessArray1[i][j];
}
}
}
File f = new File("./map.data");
FileWriter fwrite = new FileWriter(f);
for(int i=0;i<sparseArray.length;i++){
for(int j=0;j<3;j++){
fwrite.write(sparseArray[i][j]+"\t");
}
fwrite.write("\r\n");
}
fwrite.close();
FileReader fread = new FileReader("map.data");
char[] cbuf=new char[32];
int hasRead=0;
String s1="";
while((hasRead=fread.read(cbuf))>0){
s1+=new String(cbuf,0,hasRead);
}
fread.close();
System.out.println(s1);
String[] s2 = s1.split("\n");
String[] t=s2[0].split("\t");
int[][] array = new int[Integer.parseInt(t[0])][Integer.parseInt(t[1])];
for(int i=1;i<=Integer.parseInt(t[2]);i++){
String[] t1 = s2[i].split("\t");
array[Integer.parseInt(t1[0])][Integer.parseInt(t1[1])] = Integer.parseInt(t1[2]);
}
System.out.println("还原后的原始二维数组输出");
for(int[] row:chessArray1){
for(int data:row){
System.out.printf("%d\t",data);
}
System.out.println();
}
}
}