【Java导出】Graphics2D绘图并导出为dxf格式
准备步骤
下载jar包或者源码并整合到项目中
JDXF Java包
核心代码
public void exportCAD() throws IOException {
String strForDXFFormat = generateDXF();
File designFile = new File("C:\\Users\\10764\\Desktop\\dcn_topology_"+System.currentTimeMillis()+".dxf");
try{
FileWriter fileWriter = new FileWriter(designFile);
fileWriter.write(strForDXFFormat);
fileWriter.flush();
fileWriter.close();
} catch (Exception e) {
throw e;
}
}
public String generateDXF() {
DXFDocument dxfDocument = new DXFDocument("dcn topology");
dxfDocument.setUnits(4);
dxfDocument.setPrecisionDigits(8