您好,请问您使用的是哪个版本的iObjects Java组件呢?我基于您的代码编写了一个测试程序,代码如下,打成Jar包后在Linux系统上运行(iObjects Java 10.2.1),是能够正常导入obj文件的。
import com.supermap.data.*;
import com.supermap.data.conversion.DataImport;
import com.supermap.data.conversion.ImportResult;
import com.supermap.data.conversion.ImportSettingModelOSG;
import java.io.File;
public class Main {
public static void main(String[] args) {
try {
Workspace workspace = new Workspace();
Datasources datasources = workspace.getDatasources();
DatasourceConnectionInfo connectionInfo = new DatasourceConnectionInfo();
connectionInfo.setEngineType(EngineType.MEMORY);
Datasource datasource = datasources.create(connectionInfo);
if (datasource == null) {
System.out.println("新建内存数据源失败!!!");
return;
}
String filePath = args[0];
if (!new File(filePath).exists()) {
System.out.println(filePath + "文件不存在!!!");
return;
}
ImportSettingModelOSG importSettingModelOSG = new ImportSettingModelOSG(filePath, datasource);
importSettingModelOSG.setTargetEncodeType(EncodeType.BYTE);
importSettingModelOSG.setPosition(new Point3D(0, 0, 0));
importSettingModelOSG.setSourceFileCharset(Charset.DEFAULT);
DataImport importer = new DataImport();
importer.getImportSettings().add(importSettingModelOSG);
ImportResult importResult = importer.run();
if (importResult.getSucceedSettings().length == 0) {
System.out.println("导入数据失败!!!");
return;
}
Datasets datasets = datasource.getDatasets();
for (int i = 0; i < datasets.getCount(); i++) {
Dataset dataset = datasets.get(i);
System.out.println("数据集名称:" + dataset.getName());
}
} catch (Exception e) {
System.out.print(e.getLocalizedMessage());
}
}
}
建议您检查一下您的iObjects Java组件版本,可以使用上述代码尝试在Linux系统上运行看看效果。
希望可以帮到您。