62,614
社区成员
发帖
与我相关
我的任务
分享
public static void main(String[] args) throws Exception {
List<String[]> list = new ArrayList<String[]>();
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("E:/data.txt"), "utf-8"));
String line = null;
int i = 0;
String[] data = new String[4];
while ((line = br.readLine()) != null) {
if (line.equals("")) {
continue;
}
data[i % 4] = line.substring(line.indexOf(":") + 1);
if (i > 0 && i % 4 == 3) {
list.add(data);
data = new String[4];
}
i++;
}
for (String[] d : list) {
System.out.println(Arrays.toString(d));
}
}
public static void main(String[] args) {
String path = "D:\\news.txt";
String strLine;
String title = "", content = "", time = "", address = "";
BufferedReader br;
try {
File file = new File(path);
br= new BufferedReader(new FileReader(file));
while ((strLine = br.readLine()) != null) {
if (strLine.startsWith("标题")) {
title = strLine.substring(3);
} else if (strLine.startsWith("内容")) {
content = strLine.substring(3);
} else if (strLine.startsWith("时间")) {
time = strLine.substring(3);
} else if (strLine.startsWith("地点")) {
address = strLine.substring(3);
}
if (strLine.length() == 0) {
excuteSQL
.executeSql("insert into dwd(aaa,bbb,ccc,dddd) values('"
+ title
+ "','"
+ content
+ "','"
+ time
+ "','"
+ address + "');");
}
}
} catch (Exception e) {
e.printStackTrace();
}finally{
//刚才忘记了
br.close();
}
}
public static void main(String[] args) {
String path = "D:\\news.txt";
String strLine;
try {
File file = new File(path);
BufferedReader br = new BufferedReader(new FileReader(file));
while ((line = reader.readLine()) != null) {
String[] vStrs = line.split("\\:");
//String bt = vStrs[0];
if(line.startsWith("标题")){
aaa = vStrs[1];
}else if(line.startsWith("内容")){
bbb = vStrs[1];
}else if(line.startsWith("时间")){
ccc = vStrs[1];
}else{
dddd = vStrs[1];
}
excuteSQL.executeSql("insert into dwd(aaa,bbb,ccc,dddd) values('" + aaa + "','" + bbb + "','" + ccc + "','" + dddd + "');");
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
String path = "D:\\news.txt";
String strLine;
try {
File file = new File(path);
BufferedReader br = new BufferedReader(new FileReader(file));
while ((strLine = br.readLine()) != null) {
if (strLine.startsWith("标题")) {
System.out.println("你懂的...");
}
}
} catch (Exception e) {
e.printStackTrace();
}
}