java中的接口是类吗
200
2023-05-10
浅谈java 数据处理(int[][]存储与读取)
MyFile .java:
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
public class MyFile {
public static void SaveFile(String filename,int[][] arr){
try {
File file = new File(filename); //存放数组数据的文件
FileWriter out = new FileWriter(file); //文件写入流
try {
getRecord(out,arr);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
out.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
private static void getRecord(FileWriter out,int[][] arr)
throws Exception {
//将数组中的数据写入到文件中。每行各数据之间TAB间隔
for(int i=0;i for(int j=0;j out.write(arr[i][j]+"\t"); } out.write("\r\n"); } } public static void ReadFile(String filename,int[][] arr2){ try { File file = new File(filename); //存放数组数据的文件 BufferedReader in = new BufferedReader(new FileReader(file)); // try { readRecord(in,arr2); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } in.close(); } catch (Exception ex) { ex.printStackTrace(); } } private static void readRecord(BufferedReader in,int[][] arr2) throws Exception { String line; //一行数据 int row=0; //逐行读取,并将每个数组放入到数组中 while((line = in.readLine()) != null){ String[] temp = linehttp://.split("\t"); for(int j=0;j // arr2[row][j] = Double.parseDouble(temp[j]); arr2[row][j] = Integer.parseInt(temp[j]); } row++; } } } 使用: public static int imagedate[ ][ ]; MyFile.SaveFile("d:\\array.txt",imagedate);
for(int j=0;j out.write(arr[i][j]+"\t"); } out.write("\r\n"); } } public static void ReadFile(String filename,int[][] arr2){ try { File file = new File(filename); //存放数组数据的文件 BufferedReader in = new BufferedReader(new FileReader(file)); // try { readRecord(in,arr2); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } in.close(); } catch (Exception ex) { ex.printStackTrace(); } } private static void readRecord(BufferedReader in,int[][] arr2) throws Exception { String line; //一行数据 int row=0; //逐行读取,并将每个数组放入到数组中 while((line = in.readLine()) != null){ String[] temp = linehttp://.split("\t"); for(int j=0;j // arr2[row][j] = Double.parseDouble(temp[j]); arr2[row][j] = Integer.parseInt(temp[j]); } row++; } } } 使用: public static int imagedate[ ][ ]; MyFile.SaveFile("d:\\array.txt",imagedate);
out.write(arr[i][j]+"\t");
}
out.write("\r\n");
}
}
public static void ReadFile(String filename,int[][] arr2){
try {
File file = new File(filename); //存放数组数据的文件
BufferedReader in = new BufferedReader(new FileReader(file)); //
try {
readRecord(in,arr2);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
in.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
private static void readRecord(BufferedReader in,int[][] arr2)
throws Exception {
String line; //一行数据
int row=0;
//逐行读取,并将每个数组放入到数组中
while((line = in.readLine()) != null){
String[] temp = linehttp://.split("\t");
for(int j=0;j // arr2[row][j] = Double.parseDouble(temp[j]); arr2[row][j] = Integer.parseInt(temp[j]); } row++; } } } 使用: public static int imagedate[ ][ ]; MyFile.SaveFile("d:\\array.txt",imagedate);
// arr2[row][j] = Double.parseDouble(temp[j]);
arr2[row][j] = Integer.parseInt(temp[j]);
}
row++;
}
}
}
使用:
public static int imagedate[ ][ ];
MyFile.SaveFile("d:\\array.txt",imagedate);
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~