我试图使用扫描仪和分隔符获取某些文本,但我一直失败。
文件中的样本:
CROSSPLANE_AXIS=X DEPTH_AXIS=Depth INPLANE_AXIS_DIR=GUN_TARGET CROSSPLANE_AXIS_DIR=LEFT_RIGHT DEPTH_AXIS_DIR=UP_DOWN ENERGY=6.00 NOMINAL_DMAX=13.00 SSD=1000.00 SCD=450.00 BLOCK=0 WEDGE=App25x25
public static Double energy;
for (int i = 0; i < lengthOfFiles; i++) {
Scanner readAndStore = new Scanner(content);
int j = 0;
while (readAndStore.hasNextLine()) {
if (readAndStore.hasNext("ENERGY=")) {
readAndStore.useDelimiter("=");
energy = readAndStore.nextDouble();
}发布于 2014-03-11 05:34:43
因为您的所有行都是相同的格式,所以更容易
// read all lines
while (readAndStore.hasNextLine()) {
String line = readAndStore.readLine ();
// split using =
String [] words = line.split ("="); // assuming you are going to parse all lines
if (words[0].equals ("ENERGY")) {
energy = Double.parseDouble (words[1]);
}https://stackoverflow.com/questions/22317056
复制相似问题