如题

解决方案 »

  1.   

    你可以将int 型转成字符串.toString().然后用逗号分割类似写成一个csv文件,不过你保存成txt格式的,然后读的时候全处出来,直接放到一个string中,然后split成数组,再转成int
    Integer.parseInt(str[i]);
      

  2.   

    而且你可以利用DataOutputStream 和 DataOutputStream里面的writeInt()和readInt()直接读取
      

  3.   

    import java.io.*;
    public class TestDataStreams{
    public static void main(String[] args)
    {
    int[]a={1,2,3,4,5,6,7,8};
    DataInputStream dis = null;
    DataOutputStream dos = null;
    File tempFile = new File("mytemp.dat");
    if(tempFile.exists()){
    //Exit
    }
    //write
    try{
    dos = new DataOutputStream(new FileOutputStream(tempFile));
    for(int i=0;i < a.length;i++){
    dos.writeInt(a[i]);
    }
    }catch(IOException ex)
    {
    //Message 
    }finally{
    if(dos != null){
    dos.close();
    }
    }
    //read
    int[]b;
    try{
    dis = new DataInputStream(new FileInputStream(tempFile));
    for(int j=0;j < a.length;j++){
    b[j] = dis.readInt()
    }catch(IOException ex)
    {
    //Message 
    }finally{
    if(dis != null){
    dis.close();
    }
    }
    }
    }}