public class confuse {
public static void main(String[] args) {
   }
}class svyPoint {
double n, e, z;
String pt, cd;svyPoint(String mypt, double myn, double mye, double myz, String mycd) {
this.pt = mypt;
this.n = myn;
this.e = mye;
this.z = myz;
this.cd = mycd;
}public void getDataInfo(svyPoint svyPT){
int i; //indicate the line no;svyPoint[] spt; //each line of data;String[] str = spt.split(",");svypt.pt = parse.str[0];
svypt.n = parse.str[1];
svypt.e = parse.str[2];
svypt.z = parse.str[3];
svypt.cd =parse.str[4];
}}
/*如何把这些数据分开,我用了split,但是达不到目的。
 * 我想把每一行的数据分开如上面的getDataInfo(svyPoint svypt):有上面方法吗?
1,33745.3625,32288.2582,55.234,T1
2,33746.0001,32289.2748,56.234,T2
3,33744.3459,32288.8958,57.234,T3
4,33744.9835,32289.9124,58.234,T4
5,33747.3852,32291.4757,59.234,T5
6,33748.0229,32292.4922,60.234,T6
7,33746.3609,32292.1193,61.234,T7
8,33746.9941,32293.1375,62.234,T8
*/ 
上面的那些是样本数据格式,它需要用数组表示,因为很多。 
 

解决方案 »

  1.   

    Double.parseDouble(String arg0);这个方法就可以。
      

  2.   


    String[]   str   =   spt.split( ","); 
    svypt.pt = str[0]; //pt你声明的类型就是String无需转换
    svypt.n = Double.parseDouble(spt[1]);
    svypt.e = Double.parseDouble(spt[2]);
    svypt.z = Double.parseDouble(spt[3]);
    svypt.cd =str[4];//同理
      

  3.   

    Double.parseDouble() 捕捉一下异常就可以了
      

  4.   


    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.Point2D;
    import java.io.*;
    import java.text.DecimalFormat;class svyPoint {
    double sn, se, sz;
    String spt, scd; public svyPoint(String mypt, double myn, double mye, double myz, String mycd) {
    this.spt = mypt;
    this.sn = myn;
    this.se = mye;
    this.sz = myz;
    this.scd = mycd;
    }

    public void p2LineDist(svyPoint line_start, svyPoint line_end, svyPoint p0) {
    double a = line_end.sn - line_start.sn;
    double b = line_start.se - line_end.se;
    double c = line_end.se * line_start.sn  - line_start.se *line_end.sn;
    double dist;

     dist =Math.abs((p0.se * a + p0.sn *b + c)) / Math.sqrt(a*a + b*b);
    System.out.println(new DecimalFormat("0.0000").format(dist));
    }
    }public class testData { Frame f;
    TextField tf;
    Button b;
    static FileDialog fdia;
    File f0;
    static int lineNo;
    // static String line = "";
    String[] data = new String[lineNo];
    // String[] linedata;
    String[] dwPoint;
    static String[][] ptInfo; // record every point details;
    static File fdgn;

    DecimalFormat df= new DecimalFormat("0.000");  public static void main(String[] args) {
    // TODO Auto-generated method stub
    testData td = new testData();
    td.launchFrame();

    // getLineNo(fdia);
    // td.getDataInfo(fdia, lineNo); td.getfdDia();
    } public void launchFrame() {
    f = new Frame("Test Data");
    f.setBounds(100, 100, 400, 260);
    f.setLayout(new FlowLayout()); b = new Button("import");
    tf = new TextField(30); f.add(tf);
    f.add(b); fdia = new FileDialog(f, "import data", FileDialog.LOAD); myWinEvent();
    f.setVisible(true);
    } public void myWinEvent() {
    f.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e1) {
    System.exit(0);
    }
    });
    } public void getfdDia() {
    b.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e3) {
    fdia.setVisible(true); getLineNo(fdia);
    getDataInfo(fdia, lineNo);
    }
    }); } // get the selected file line no by file dialog;
    public static int getLineNo(FileDialog fd1) {
    String dirPath = fd1.getDirectory();
    String fileName = fd1.getFile(); // do judgment of select file or not.
    if (dirPath == null || fileName == null) {
    // return;
    } fdgn = new File(dirPath, fileName);
    try {
    FileReader fr = new FileReader(fdgn);
    LineNumberReader lnr = new LineNumberReader(fr); while ((lnr.readLine()) != null) {
    lineNo = lnr.getLineNumber();
    //System.out.println("DWLineNo... " + lineNo);
    } fr.close();
    lnr.close();
    } catch (IOException e4) {
    throw new RuntimeException("Error...");
    }
    return lineNo;
    } @SuppressWarnings("null")
    public void getDataInfo(FileDialog fd2, int lineNo) { int linenum = lineNo;
    String dirPath = fd2.getDirectory();
    String fileName = fd2.getFile(); // do judgment of select file or not.
    if (dirPath == null || fileName == null) {
    //return;
    }
    // System.out.println(dirPath + "..." + fileName);
    fdgn = new File(dirPath, fileName); FileInputStream in = null;
    BufferedReader br = null; dwPoint = new String[linenum]; try {
    in = new FileInputStream(fdgn);
    br = new BufferedReader(new InputStreamReader(in)); for (int j = 0; j < dwPoint.length; j++) {
    try {
    dwPoint[j] = br.readLine();
    } catch (IOException e) {
    e.printStackTrace();
    }
    } } catch (FileNotFoundException e) {
    e.printStackTrace();
    } finally {
    try {
    in.close();
    } catch (IOException e) {
    e.printStackTrace();
    }
    } String[] pts = null; // Temporary store each property of the data info ptInfo = new String[dwPoint.length][];

    svyPoint svypt[] = null;

    for (int n = 0; n < dwPoint.length; n++) { pts = dwPoint[n].split(",");

    svypt[n].spt = pts[0];
    svypt[n].sn = Double.parseDouble(pts[1]);
    svypt[n].se = Double.parseDouble(pts[2]);
    svypt[n].sz = Double.parseDouble(pts[3]);
    svypt[n].scd = pts[4];

    //System.out.println(fileName + " Data pts" + "[" + n + "]" + svypt[n].spt); }

    for(int i=0;i<dwPoint.length;i++) {
    System.out.println(fileName + " Data pts" + "[" + i + "]" + svypt[i].spt);
    }
    }}能不能帮我看一下。用下面的这个八个点做外部文件吧。
    1,33745.3625,32288.2582,55.234,T1 
    2,33746.0001,32289.2748,56.234,T2 
    3,33744.3459,32288.8958,57.234,T3 
    4,33744.9835,32289.9124,58.234,T4 
    5,33747.3852,32291.4757,59.234,T5 
    6,33748.0229,32292.4922,60.234,T6 
    7,33746.3609,32292.1193,61.234,T7 
    8,33746.9941,32293.1375,62.234,T8 
      

  5.   

    no body answer for me?