我目前正在嘗試從座標文件中拉出數據,將其作爲字符串轉換爲矢量,然後將數據從該矢量中拉出,並將其從字符串轉換爲一系列點,然後將其放入第二個Vector。從矢量傳輸到矢量
我無法在網上找到解決方案。我有第一個向量的代碼,並將代碼轉換爲雙向以供向量使用。但我需要知道如何從第一個向量中提取數據!
我是新來的Java所以我很抱歉,如果這是一個非常簡單的問題!
這是我寫的代碼迄今..我沒有驅動程序,所以我不能測試它。 提前抱歉!
import java.io.*;
import java.util.*;
public class PointField {
String ID;
Vector<String> v;
Vector<Point> v1;
public PointField() {
v = new Vector<String>();
this.v1 = new Vector<Point>();
this.ID = new String();
}
public String getID() {
return this.ID;
}
public Vector<String> getv() {
return v;
}
public Vector<Point> getv1() {
return this.v1;
}
//Read all the lines from a file
public Vector<String> getString(String fileName) throws Exception{
// Variable declarations
File inputFile;
FileInputStream inputStream;
InputStreamReader inputStreamRead;
BufferedReader br;
// Make the objects needed
inputFile = new File(fileName);
inputStream = new FileInputStream(inputFile);
inputStreamRead = new InputStreamReader(inputStream);
br = new BufferedReader(inputStreamRead);
// read all the lines and call getPoint method
while (this.ID!= null) {
this.ID = br.readLine();
v.addElement(this.ID);
}
// DOESNT WORK FROM HERE Get String out of Vector v and make it return it as String ID
public String getString(Vector<String> v) {
Iterator<String> it;
it = this.v.iterator();
while(it.hasNext()) {
this.ID = (String)it.next();
}
return ID;
}
//* Get String into two doubles and assign to x,y variables
public Point makePoints(String s, String delim) {
while (st.hasMoreTokens()){
st = new StringTokenizer(s, delim);
p = new Point(x,y);
x = Double.parseDouble(st.nextToken());
y = Double.parseDouble(st.nextToken());
}
return p;
}
}
後你這麼遠。 – 2012-02-27 18:04:41
香港專業教育學院增加了代碼! – user7160 2012-02-27 18:12:27
IVE提高了代碼,所以它的工作原理,直到迭代器位! – user7160 2012-02-27 19:07:32