All pastes #760208 Raw Edit

test

public java v1 · immutable
·published 2007-11-03 20:45 UTC
rendered paste body
/****************************************************************************************************** * This program is free software: you can redistribute it and/or modify *  it under the terms of the GNU General Public License as published by *  the Free Software Foundation, either version 3 of the License, or *  any later version. * *  This program is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *  GNU General Public License for more details. * *  You should have received a copy of the GNU General Public License *  along with this program.  If not, see <http://www.gnu.org/licenses/>. * ****************************************************************************************************** *  Ce programme permet d'extraire la totalité des emails existants dans un  *  fichier texte nommé Myfile.txt et gener deux fichiers Resultat.txt & NonTrier.txt *  Créer Par: D3vDiL Merci à : Usr[Denied] *  Nom fichier : extract.java  *  version: 0.1 ********************************************************************************************************/import java.io.*;import java.util.*;import java.util.regex.*;class extract{	public static void main(String[] arg){			// ouverture du fichier		BufferedReader IN=null;		try {			IN=new BufferedReader(new FileReader("myfile.txt"));		} catch (Exception e) { Erreur(e,1); }				// ouverture du fichier temp pour enregistré		PrintWriter temp=null;	    try{    	  temp=new PrintWriter(new FileWriter("NonTrier.txt"),true);    	} catch (Exception e){ Erreur(e,2); }    			String ligne=null;		Pattern pattern;		Matcher matcher;		int line=0;				// parcoure du fichier qui contient les emails			try {			while((ligne=IN.readLine())!=null) {				// Correspondent à l'adresse email				pattern = Pattern.compile("[a-z0-9\\-_\\.]++@[a-z0-9\\-]++(\\.[a-z0-9\\-]++)++"); 				Matcher mail = pattern.matcher(ligne); 				int gc = mail.groupCount();				while(mail.find()){										for (int i=0; i<gc; i++ ){						temp.println(mail.group(i));						line++;					}				}			}		} catch (Exception e) { Erreur(e,3); }					// ouverture du fichier temp		BufferedReader temp1=null;		try {			temp1=new BufferedReader(new FileReader("NonTrier.txt"));		} catch (Exception e) { Erreur(e,4); }				// fichier Trier		PrintWriter res=null;	    try{    	  res=new PrintWriter(new FileWriter("Resultat.txt"),true);    	} catch (Exception e){ Erreur(e,2); }				String chaine=null;		String tab[] = new String[line];		int i=0;				// parcoure deu fichier temp et affecter chaque string 		// dans une case de tab[]		try {				while ((chaine=temp1.readLine())!= null) {				tab[i] = chaine;				i++;			}		}catch (Exception e) { Erreur(e,5); }				// trier le le tableau		Arrays.sort(tab);		for (i=0; i<tab.length; i++ ){			System.out.println(tab[i]);			res.println(tab[i]);		}		// fermerture des deux fichiers		try { res.close(); } catch (Exception e){ Erreur(e,4); }		try { temp.close(); } catch (Exception e){ Erreur(e,4); }	}	private static void Erreur(Exception e, int code){		System.err.println("Erreur : "+e);		System.exit(code);	}}