我要把TXT里的内容插入到数据库。TXT格式是这样:
device=55555555
id=6
userid=0
time=2009.05.17 12:48:05
log_pic=00000000-1242564485.jpg
device=55555555
id=5
userid=0
time=2009.05.17 12:46:55
log_pic=00000000-1242564415.jpg
device=55555555
id=4
userid=0
time=2009.05.17 12:46:24
log_pic=00000000-1242564384.jpg最好给段代码。
device=55555555
id=6
userid=0
time=2009.05.17 12:48:05
log_pic=00000000-1242564485.jpg
device=55555555
id=5
userid=0
time=2009.05.17 12:46:55
log_pic=00000000-1242564415.jpg
device=55555555
id=4
userid=0
time=2009.05.17 12:46:24
log_pic=00000000-1242564384.jpg最好给段代码。
public static void main(String[] args) {
File ft = new File("E:\\temp\\test.txt");
StringBuffer sb = new StringBuffer();
try {
String str = "";
String device = "";
String id = "";
String userid = "";
String time = "";
String log_pic = "";
InputStream is = new FileInputStream(ft);
BufferedReader in = new BufferedReader(new InputStreamReader(is, "GBK"));
while (null != (str = in.readLine())) {
if(str.indexOf("device") != -1) {
device = str.substring(str.lastIndexOf("=") + 1, str.length()).trim();
}else if(str.indexOf("id") != -1) {
id = str.substring(str.lastIndexOf("=") + 1, str.length()).trim();
}else if(str.indexOf("userid") != -1) {
userid = str.substring(str.lastIndexOf("=") + 1, str.length()).trim();
}else if(str.indexOf("time") != -1) {
time = str.substring(str.lastIndexOf("=") + 1, str.length()).trim();
}else if(str.indexOf("log_pic") != -1) {
log_pic = str.substring(str.lastIndexOf("=") + 1, str.length()).trim();
//在这里进行写数据库操作
System.out.println(device + "#" + id + "#" + userid + "#" + time + "#" + log_pic);
}
}
} catch (Exception e) {
System.out.println("读数据错误");
}
}