淺談java 數(shù)據(jù)處理(int[][]存儲與讀取)
更新時間:2017年06月04日 10:01:06 投稿:jingxian
下面小編就為大家?guī)硪黄獪\談java 數(shù)據(jù)處理(int[][]存儲與讀取)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
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); //存放數(shù)組數(shù)據(jù)的文件
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 {
//將數(shù)組中的數(shù)據(jù)寫入到文件中。每行各數(shù)據(jù)之間TAB間隔
for(int i=0;i<arr.length;i++){
for(int j=0;j<arr[0].length;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); //存放數(shù)組數(shù)據(jù)的文件
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; //一行數(shù)據(jù)
int row=0;
//逐行讀取,并將每個數(shù)組放入到數(shù)組中
while((line = in.readLine()) != null){
String[] temp = line.split("\t");
for(int j=0;j<temp.length;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);
以上這篇淺談java 數(shù)據(jù)處理(int[][]存儲與讀取)就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- 淺談Java中的集合存儲數(shù)據(jù)后,輸出數(shù)據(jù)的有序和無序問題
- Java 實現(xiàn)Redis存儲復雜json格式數(shù)據(jù)并返回給前端
- java8中NIO緩沖區(qū)(Buffer)的數(shù)據(jù)存儲詳解
- Java字節(jié)與字符流永久存儲json數(shù)據(jù)
- 相冊管理系統(tǒng)(Java表單+xml數(shù)據(jù)庫存儲)
- JSON復雜數(shù)據(jù)處理之Json樹形結構數(shù)據(jù)轉Java對象并存儲到數(shù)據(jù)庫的實現(xiàn)
- java實現(xiàn)表格數(shù)據(jù)的存儲
相關文章
Spring容器的創(chuàng)建過程之如何注冊BeanPostProcessor詳解
關于BeanPostProcessor 各位一定不陌生,今天整理的這篇文章總結了如何注冊BeanPostProcessor,文中有非常詳細的圖文示例,需要的朋友可以參考下2021-06-06
Struts2 ActionContext 中的數(shù)據(jù)詳解
這篇文章主要介紹了Struts2 ActionContext 中的數(shù)據(jù)詳解,需要的朋友可以參考下2016-07-07

