Advertisement
Guest User

lerVotacoes

a guest
Nov 25th, 2015
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. public static void readVotesFileInfo() throws FileNotFoundException {
  2. Scanner scanner = new Scanner (System.in);
  3. System.out.println("Qual é o nome do ficheiro?");
  4. String fileName = scanner.nextLine();
  5. File f = new File(fileName);
  6. int nlinhas = 0;
  7. String[]votes = new String[Savop.MAX_DEPUTADOS];
  8. Scanner fInput = new Scanner(f);
  9. while (fInput.hasNext() && nlinhas < Savop.MAX_DEPUTADOS) {
  10. String line = fInput.nextLine();
  11. if (line.length() == 6){
  12. votes[nlinhas] = line.substring(line.length()-1);
  13. nlinhas++;
  14. }else{
  15. System.out.println("Informação incorreta na linha " + (nlinhas+1));
  16. }
  17.  
  18. }
  19. for (int i = 0; i < nlinhas; i++){
  20. System.out.println(votes[i]);
  21. }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement