📄 readwpt.java
字号:
package net.aetherial.gis.database.readFile;
import java.io.*;
import net.aetherial.gis.database.access.Connect;
import java.sql.*;
public class ReadWpt {
File f = null;
public String name;
public String describe;
public double lat, lon, alt;
public ReadWpt(String filePath) {
f = new File(filePath);
}
public void read() { //读取文件,并输出到控制台
try {
FileReader fr = new java.io.FileReader(f);
BufferedReader br = new BufferedReader(fr);
String line = "";
int row = 0, start = 10;
Connect c = new Connect();
Statement sql = c.getStatement();
String sqlString = "";
while (true) {
if ( (line = br.readLine()) == null) {
break;
}
if (row >= start) {
line = line.trim();
//=======================================这里写把此句分开的程序
//System.out.println(line);
this.getPoint(line);
sqlString =
"INSERT INTO waypoint(name,lat,lon,alt,describe) VALUES('" +
this.name + "','" + this.lat + "','" + this.lon + "','" +
this.alt + "','" + this.describe + "')";
sql.executeUpdate(sqlString);
//========================================
}
row++;
}
c.setConnClose();
fr.close();
br.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
public void getPoint(String str) { //W 0001 N3182.00462 E11730.20034 00034 27- 08-04 09:10
//******************************/01234567890123456789010123456789012345678901234567890123456789
String name = str.substring(3, str.lastIndexOf("N") - 1).trim();
String temp1 = str.substring(str.lastIndexOf("N") + 1,
str.lastIndexOf("E") - 1).trim();
String temp2 = str.substring(str.lastIndexOf("E") + 1,
str.lastIndexOf("E") + 12).trim();
String temp3 = str.substring(str.lastIndexOf("E") + 12,
str.lastIndexOf("E") + 19).trim();
String describe = str.substring(str.length() - 15, str.length()).trim();
double lat = Double.parseDouble(temp1) / 100;
double lon = Double.parseDouble(temp2) / 100;
double alt = this.getAlt(temp3);
this.name = name;
this.describe = describe;
this.lat = lat;
this.lon = lon;
this.alt = alt;
System.out.println("name:(" + name + "),lat:(" + lat + "),lon:(" + lon +
"),alt:(" + alt + "),describe:(" + describe + ")");
}
public double getAlt(String altString) {
int pos = altString.indexOf("-");
if (pos == -1) { //说明是正数
return Double.parseDouble(altString);
}
else {
altString = altString.substring(pos, altString.length());
return Double.parseDouble(altString);
}
}
public static void main(String args[]) {
ReadWpt rt = new ReadWpt(
"C:\\Documents and Settings\\Administrator\\桌面\\hangdian.wpt");
rt.read();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -