Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- File file = new File("pback.txt");
- Scanner in = null;
- Scanner scanner = null;
- try {
- in = new Scanner(file);
- } catch (FileNotFoundException e) {
- System.out.println ("File not found!");
- }
- System.out.println(in);
- List<String> ids = new ArrayList<String>();
- List<String> usr = new ArrayList<String>();
- List<String> desc = new ArrayList<String>();
- List<String> dep = new ArrayList<String>();
- List<String> pri = new ArrayList<String>();
- List<String> est = new ArrayList<String>();
- List<String> acrit = new ArrayList<String>();
- String currentId = "<id>";
- String acritStr = "";
- while(in.hasNextLine()) {
- String currentLine = in.nextLine();
- if(currentLine.startsWith("<")) {
- currentId = currentLine;
- continue;
- }
- switch(currentId) {
- case "<id>":
- ids.add(currentLine);
- break;
- case "<usr>":
- usr.add(currentLine);
- break;
- case "<desc>":
- desc.add(currentLine);
- break;
- case "<dep>":
- dep.add(currentLine);
- break;
- case "<pri>":
- pri.add(currentLine);
- break;
- case "<est>":
- est.add(currentLine);
- break;
- case "<acrit>":
- if(currentLine.isEmpty()) {
- acrit.add(acritStr);
- acritStr = "";
- } else {
- acritStr += "\n" + currentLine;
- }
- break;
- }
- }
- System.out.println(ids.size());
- System.out.println(usr.size());
- System.out.println(dep.size());
- System.out.println(pri.size());
- System.out.println(acrit.size());
- System.out.println(est.size());
- System.out.println(
- ids.size() == usr.size() &&
- ids.size() == dep.size() &&
- ids.size() == pri.size() &&
- ids.size() == acrit.size() &&
- ids.size() == est.size()
- );
- StringBuilder sb = new StringBuilder();
- for(int i = 0 ; i < ids.size() ; i++ ) {
- String id = ids.get(i);
- String us = usr.get(i);
- String ds = desc.get(i);
- String dp = dep.get(i);
- String pr = pri.get(i);
- String es = est.get(i);
- String acr = acrit.get(i);
- sb.append("ID: ");
- sb.append(id);
- sb.append("\nUser Story: ");
- sb.append(us);
- sb.append("\nPriority: ");
- sb.append(pr);
- sb.append("\nEst. cost: ");
- sb.append(es);
- sb.append("\nDescription: ");
- sb.append(ds);
- sb.append("\nAcceptance critera: ");
- sb.append(acr);
- sb.append("\nDependency: ");
- sb.append(dp);
- sb.append("\n\n");
- }
- try {
- FileWriter fstream = new FileWriter("out.txt");
- BufferedWriter out = new BufferedWriter(fstream);
- out.write(sb.toString());
- //Close the output stream
- out.close();
- } catch (Exception e){//Catch exception if any
- System.err.println("Error: " + e.getMessage());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement