0

我期待解析 LAS 文件(Log ASCII 标准),这种类型的文件具有不同语法的不同部分,例如这里:

"file.las"
~V
VERS  .   3.00    : Comments
DLM   .   COMMA
~Curve
RHOB.M
~Data
1000.5,  35.2
1001.0,  40.6

这是我目前正在解析文件的方法,我为每种语法使用不同的 for 循环。

BufferedReader file = new BufferedReader(new FileReader(path));

System.out.print("Searching ~V");
for (String line = file.readLine(); line != null; line = file.readLine()) {
  if(line.contains("~V")){
    System.out.println("Success");
    break;
  }else{
    //Do Nothing
  }
}

System.out.print("Searching VERS");
for (String line = file.readLine(); line != null; line = file.readLine()) {
  line = line.trim();
  if(line.startsWith("VERS.")){
  line = line.replaceAll(" ", "");
  String lineWithoutComment = line.split(":")[0];
  lasFileVO.setVersion(lineWithoutComment);
  break;
  }else{
     //Do Nothing
  }
}

if(lasFileVO.getVersion.startWith("3.0")){
  System.out.print("Searching DLM");
  //For loop
}

解析工作正常,我发现其他开发人员很容易理解(这是一件好事)。

有没有更好的方法来解析文件,包含具有不同语法的不同部分,然后是我的 For 循环系列?

编辑:

我已经看到了 while 循环方式,但我不知道如何实现它:

while ( (line = bufRead.readLine()) != null)
{    
    
}

...在不同位置使用不同语法的文件,而无需添加大量条件。使用 for 循环列表,我不需要为每一行检查很多条件。

4

1 回答 1

-1

你有这个项目可以帮助你解析 LAS 文件

http://www.jwitsml.org/dlis.html

这是使用此库的示例:

 File file = new File("data.las");

 // Instantiate a reader and read the LAS file
 LasFileReader reader = LasFileReader(file);
 LasFile lasFile = reader.readFile();

 // Loop over all curves
 for (LasCurve curve : lasFile.getCurves()) {
   System.out.println("Curve name..: " + curve.getName());
   System.out.println("Description.: " + curve.getDescription());
   System.out.println("Unit........: " + curve.getUnit());
   System.out.println("value type..: " + curve.getValueType());
   // The curve values are accessed by curve.getValue(index)
 }
于 2015-03-24T09:58:56.773 回答