Pedir ao utilizador para imprimir!

0 respostas
R
oi ai esta meu codigo
import java.io.*;       
      import java.util.HashMap;
      import java.util.ArrayList;  
      import java.util.List;  
      import java.util.Map;  
      //import javax.swing.JOptionPane; 


               
    public class Dados{           
             
        
        //"args" é um array de String onde cada elemento é um argumento passado pela linha de comando momento na "inicialização" da execução.
        public static void main(String[] args){           
            
            
           Map<Integer, List<String>> mapLines= new HashMap<Integer, List<String>>();     
         try {           
           //leitura do ficheiro, prepara-o para ser aberto
           BufferedReader in = new BufferedReader(new FileReader("conteudo.txt"));           
           String str;       
           int i = 0;       
           //vai percorrer todo o ficheiro
           while((str = in.readLine()) != null)           
           {                 
               if(str.startsWith("#"))
               {                 
                   str= "";                 
               }                 
               else{     //esta a dividir a frase em varias strings imprimindo o seu resultado
                    List<String> values = new ArrayList<String>();     
                        String words[] = str.split(";");         
                        for(String word : words) {         
                            values.add(word); 
                            System.out.println(word);
                        }     
                        mapLines.put(i, values);     
                        i++;     
               }   
         }// fim do while                           
           in.close();           
       }  catch (IOException e){           
           // possiveis erros são tratatos aqui 
           //JOptionPane.showMessageDialog(null, this.word, "NÂO FOI POSSÍVEL ABRIR O SEU FICHEIRO", JOptionPane.ERROR_MESSAGE);  
           System.out.println("ERRO-->NÃO FOI ENCONTRADO O SEU FICHEIRO DE DESTINO,TENTE DE NOVO");        
       }      
       // Apresenta o contéudo do Map     
       Map<Integer, List<String>> m = new HashMap<Integer, List<String>>();     
       for(Integer key : m.keySet()) {     
           for(String word : m.get(key)) {     
               System.out.println(word);     
           }     
       }              
       } 
        public static void main2(String[] args){           
            
            
            Map<Integer, List<String>> mapLines= new HashMap<Integer, List<String>>();     
         try {           
                  
           BufferedReader in2 = new BufferedReader(new FileReader("conteudo2.txt"));           
           String str;       
           int i = 0;       
           while((str = in2.readLine()) != null)           
           {                 
               if(str.startsWith("#"))                 
               {                 
                   str= "";                 
               }                 
               else{     //esta a dividir a frase em varias strings
                        List<String> values = new ArrayList<String>();     
                        String words[] = str.split(" ");         
                        for(String word : words) {         
                            values.add(word);
                            System.out.println(word);
                        }     
                        mapLines.put(i, values);     
                        i++;     
               }   
         }// fim do while                           
           in2.close();           
       }  catch (IOException e){           
           // possiveis erros são tratatos aqui  
           System.out.println("ERRO-->NÃO FOI ENCONTRADO O SEU FICHEIRO DE DESTINO,TENTE DE NOVO");
       }      
       // Apresenta o contéudo do Map     
       Map<Integer, List<String>> m = new HashMap<Integer, List<String>>();     
       for(Integer key : m.keySet()) {     
           for(String word : m.get(key)) {     
               System.out.println(word);     
       
            }   

        }
    }
}

e tenho por exemplo este ficheiro

961234567 253883377 24:05:2011 10:30:10 068 16 13
963456789 253883355 28:05:2011 12:15:17 088 12 09
963456789 253883377 29:05:2011 17:00:00 120 14 11
969876666 253883377 30:05:2011 10:05:34 070 11 09
961234567 253883377 31:05:2011 22:30:05 066 14 11
961234567 253883377 02:06:2011 14:19:41 076 15 13
963456789 253883377 05:06:2011 11:33:34 085 07 06

e queria que fosse pedido ao utilizador que dados e que ele quer imprimir. por exemplo...pedirmos para imprimir todos os dados com o numero 961234567

abraços

Criado 24 de junho de 2011
Respostas 0
Participantes 1