67,513
社区成员
发帖
与我相关
我的任务
分享
package test0320;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
public class TopicStorage {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
File file = new File("E:\\test\\topic.txt");
String sbf[][] = new String[100][6];
try {
BufferedReader br = new BufferedReader(new InputStreamReader(
new FileInputStream(file)));
String str = null;
int i = 0;
int j = 0;
while ((str = br.readLine()) != null) {
if ("".equals(str.trim()))//空行跳到下行
continue;
if (j < 5) {// 题目和选项
sbf[i][j] = str.substring(2);// 可以写成 str.substring(str.lastIndexOf("、"))
}
if (j == 5) {//答案
sbf[i][j] = str.substring(8);//同理str.substring(str.lastIndexOf(":"))
}
j++;
if (j == 6) {
i++;
j = 0;
}
}
for (int x = 0; x < 100; x++) {
for (int y = 0; y < 6; y++) {
System.out.println("++++++++++++ " + sbf[x][y]);
/***
* 调用插入数据库的方法 sbf[x][y]
*/
}
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
input.split("[A|B|C|D]、");
得到含5个元素的数组,首元素是题目,其次依序是选项