有一个float的数组但是把这个数组读到一个文件里后,那些浮点数变成了[F@e09713这种字符,是怎么回事呢?我学java不久,请指教,谢谢!

解决方案 »

  1.   

    你想在文件中仍看到这些数值?
    如果这样的话,那么在存进文件之前要把他们转成String
    否则,你存入的话调用的是该数组默认的toString()方法,就是你看到的那个字符串。
      

  2.   

    float转String,可以用String temp = Float.toString(你要转的float数值)
      

  3.   

    原文件中的数据是这样的
    depth,         AC,         CAL,         CNL,          GR,         POR, 
       2050.0000  -99999.0000      21.4500   -9999.0000      88.7670       0.0010
       2050.1250  -99999.0000      21.3440      27.4830      88.7670       0.0010
       2050.2500  -99999.0000      21.2880      27.5200      91.7620       0.0010
       2050.3750  -99999.0000      21.1990      27.2690      94.5450       0.0010
       2050.5000  -99999.0000      21.1630      26.6400      96.0920       0.0010
    读到另一个文件里变成这样了
    depth,         AC,         CAL,         CNL,          GR,         POR,[F@c17164[F@1fb8ee3[F@61de33[F@14318bb[F@ca0b6[F@10b30a7[F@1a758cb[F@1b67f74部分源码:import java.util.*;
    import java.io.*;public class FileOperation {
    private String txtPath; public FileOperation() {
    txtPath = null;
    } public void setTxtPath(String txtPath) {
    this.txtPath = txtPath;
    }
    public String getTxtPath() {
    return txtPath;
    } public void readDataFromTxt( ) {
    try {
    File read = new File(getTxtPath()); //根据路径构造一个File对象
    String path=read.getPath();//文件路径
    String path2=path.substring(0, path.lastIndexOf("\\")+1);

    String fileNameRead_txt=path.substring(path.lastIndexOf("\\") + 1);
    String fileNameRead=fileNameRead_txt.substring(0,fileNameRead_txt.lastIndexOf("."));
    String fileNameWrite=fileNameRead+"Temp.txt";
    String pathWrite=path2+fileNameWrite;
    /*
    System.out.println(path);
    System.out.println(fileNameRead);
    System.out.println(pathWrite);
    */
    File write=new File(pathWrite);

    if(!write.exists()){//创建一个临时文件
    write.createNewFile();
    }else if(write.exists()){
    write.delete();
    write.createNewFile();
    }


    if (!read.isFile()) { //判断File对象是不是一个文件,如果不是就抛出异常
    throw new IOException("This is not a file!");
    }
    //读取数据至内存
    BufferedReader in = new BufferedReader(new FileReader(read));//构建一个BufferedReader对象,利用BufferedReader对象的readLine()方法读取一行数据
    BufferedWriter bw = new BufferedWriter(new FileWriter(write));//写
    //PrintWriter fout = new PrintWriter(new BufferedWriter(new FileWriter(write))); 

    String lineOfRead = null;//文件中的一行数据
    String[] columnName = null;//表格的列属性名


    if ((lineOfRead = in.readLine()) != null && !lineOfRead.trim().isEmpty()) { //读取一行数据并判断是否为空
    bw.write(lineOfRead.trim()+"\r\n");
    columnName = lineOfRead.trim().split(","); //利用String类的split()方法划分出列名,具体split方法参考jdk文档 for (int i = 0; i < columnName.length; i++) {
    columnName[i] = columnName[i].trim();

    }
    }

    while ((lineOfRead = in.readLine()) != null && !lineOfRead.trim().isEmpty()) {
    //构造一个StringTokenizer对象,切分出一个一个数据
    StringTokenizer stn = new StringTokenizer(lineOfRead);
    String[] data = new String[stn.countTokens()];

    float[] f=new float[stn.countTokens()];


    for (int i = 0; i < f.length; i++) {
    data[i] = stn.nextToken();
    f[i]=Float.parseFloat(data[i]);
    System.out.print(f[i]+"\t\t");
    }
    System.out.print("\n");
    bw.write(f.toString()+"\r\n");
    }
    in.close();
    bw.close(); } catch (Exception ex) {
    System.out.println(ex.getMessage());
    ex.printStackTrace();
    } }
    }