⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readquesion.java

📁 一个考试系统 基于xml数据库 没有利用任何工具读取数据库
💻 JAVA
字号:
import java.util.*;
import java.io.*;


public class ReadQuesion{
	public static Vector readQuesion(){
		
		Vector<Object> v = new Vector<Object>();
		try{
			FileReader fr = new FileReader("data.xml");
			BufferedReader br = new BufferedReader(fr);	
			
			while(true){
				Question q = new Question();
				String s = br.readLine();
				while(s!=null && (!s.equals("<question>"))){
					s = br.readLine();	
				}
				s = br.readLine();
				if(s!=null&&!s.equals("<note>")){
					s = br.readLine();
				}
				if(s == null) break;
				s = br.readLine();
				q.setNote(s);
				s = br.readLine();
				if(s!=null&&!s.equals("</note>")){
					s = br.readLine();
				}
				s = br.readLine();
				if(s!=null&&!s.equals("<detail>")){
					s = br.readLine();
				}
				s = br.readLine();
				String sb ="";
				while(s!=null&&!s.equals("</detail>")){
					sb = sb+s+"\n";
					s = br.readLine();
				}
				q.setDetail(sb);
				s = br.readLine();
				
				if(s!=null&&!s.equals("<choice>")){
					s = br.readLine();
				}
				s = br.readLine();
				Vector<String> vc = new Vector<String>();
				while(s!=null&&!s.equals("</choice>")){
					vc.add(s);
					s = br.readLine();
				}
				q.setChoice(vc);
				s = br.readLine();
				if(s!=null&&!s.equals("<answer>")){
					s = br.readLine();
				}
				s = br.readLine();
				q.setStandardAnswer(s);
				
				s = br.readLine();
				if(s!=null&&!s.equals("</answer>")){
					s = br.readLine();
				}
				s = br.readLine();
				if(s!=null&&!s.equals("</question>")){
					s = br.readLine();
				}
				v.add(q);
			}
			
		}catch(Exception e){
			e.printStackTrace();
		}
		
		
		return v;
		
	}
	
	public static void main(String[] args){
		Vector v = ReadQuesion.readQuesion();
		for (int i = 0; i<v.size(); i++) {
			Question q = (Question)v.get(i);
			System.out.println (q.getDetail());
			System.out.println ("------------------------");
	    }
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -