IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Entrée/Sortie Java Discussion :

Optimisation script ouverture URL depuis fichier texte


Sujet :

Entrée/Sortie Java

  1. #1
    Membre régulier Avatar de vertebre
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2015
    Messages
    184
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2015
    Messages : 184
    Points : 111
    Points
    111
    Par défaut Optimisation script ouverture URL depuis fichier texte
    Bonjour,

    J'ai un fichier texte qui contient des URL seulement sur certaines lignes, quand il y a une URL de présente c'est la seule chaine de caractère sur la ligne.
    J'ai récupéré un peu de code sur ce forum: dans la FAQ java et dans un post pour faire un pgr qui m'ouvre les URL trouvées de ce fichier.

    Comme que mon fichier contient plus de 200 URL cela met du temps et freeze mon pc, ce que je peux comprendre.

    Comment optimiser l'ouverture des URL pour faire en sorte que mon système ne soit pas ralenti ?

    Voici ce code où j'ai rajouté quelques trucs :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileReader;
    import java.io.IOException;
    import java.util.Scanner;
     
    public class BrowserControl
    {
     
    	// Fonction qui affiche une URL sur Windows ou UNIX
        public static void displayURL(String url)
        {
            boolean windows = isWindowsPlatform();
            String cmd = null;
            try
            {
                if (windows)
                {
                    // cmd = 'rundll32 url.dll,FileProtocolHandler http://...'
                    cmd = WIN_PATH + " " + WIN_FLAG + " " + url;
                    Process p = Runtime.getRuntime().exec(cmd);
                }
                else
                {
                    // Under Unix, Netscape has to be running for the "-remote"
                    // command to work.  So, we try sending the command and
                    // check for an exit value.  If the exit command is 0,
                    // it worked, otherwise we need to start the browser.
                    // cmd = 'netscape -remote openURL(http://www.javaworld.com)'
                    cmd = UNIX_PATH + " " + UNIX_FLAG + "(" + url + ")";
                    Process p = Runtime.getRuntime().exec(cmd);
                    try
                    {
                        // wait for exit code -- if it's 0, command worked,
                        // otherwise we need to start the browser up.
                        int exitCode = p.waitFor();
                        if (exitCode != 0)
                        {
                            // Command failed, start up the browser
                            // cmd = 'netscape http://www.javaworld.com'
                            cmd = UNIX_PATH + " "  + url;
                            p = Runtime.getRuntime().exec(cmd);
                        }
                    }
                    catch(InterruptedException x)
                    {
                        System.err.println("Error bringing up browser, cmd='" +
                                           cmd + "'");
                        System.err.println("Caught: " + x);
                    }
                }
            }
            catch(IOException x)
            {
                // couldn't exec browser
                System.err.println("Could not invoke browser, command=" + cmd);
                System.err.println("Caught: " + x);
            }
        }
     
    	// Attributs
    	public String pathFolder = "C:\\files\\"; 		// Stocke le chemin d'accès au dossier du fichier
    	public static String urlName="";				// Stocke le nom de l'URL en cours d'affichage
     
    	// Méthode qui détermine si l'application est lançé sur un OS un windows ou pas
        public static boolean isWindowsPlatform()
        {
            String os = System.getProperty("os.name");
            if ( os != null && os.startsWith(WIN_ID))
                return true;
            else
                return false;
     
        }
     
     // Fonction permettant de lire un fichier ligne par ligne et d'afficher les URL contenant http ou https
     	public static void openURLForAllLine(File fileForFileName){
     
     
     		// On crée le 
     		// Lire un fichier ligne par ligne
     		try{
     			// Création du flux bufférisé sur un FileReader, immédiatement suivi par un 
     			// try/finally, ce qui permet de ne fermer le flux QUE s'il le reader
     			// est correctement instancié (évite les NullPointerException)
     			BufferedReader buff = new BufferedReader(new FileReader(fileForFileName));
     
     			try {
     			String line;
     			// Lecture du fichier ligne par ligne. Cette boucle se termine
     			// quand la méthode retourne la valeur null.
     			while ((line = buff.readLine()) != null) {
     				// Condition si http ou https présent comme occurence dans la ligne en cours
     				if (line.contains("http") && line.contains("https")) {
     					// on stocke la ligne dans la variable urlName
     					urlName=line;
     					// On affiche l'URL dans le navigateur
     					displayURL(urlName);
     				}
     			}
     			} finally {
     			// dans tous les cas, on ferme nos flux
     			buff.close();
     			}
     			} catch (IOException ioe) {
     			// erreur de fermeture des flux
     			System.out.println("Erreur --" + ioe.toString());
     			}
     
     	}
     
     
        /**
         * Main principale :
         * Lancement du programme
         * On récupère le dossier que l'utilisateur aura spécifié
         * On récupère le nom du fichier que l'utilisateur aura spécifié
         * On appelle la fonction qui ouvre les URL
         */
     
        public static void main(String[] args)
        {
        	Scanner sc = new Scanner(System.in);
     
        	// Demander le dossier du fichier (se termine par un \)
        	 		System.out.println("Entrer le nom du dossier où se situe le fichier avec un \\ en fin");
        	 		String pathFolder = sc.nextLine();
        	// Demander le nom du fichier avec son extension
        	 		System.out.println("Entrer le nom du fichier avec son extension");
        	 		String fileName = sc.nextLine();
        	 		File pathFile= new File(pathFolder+fileName); 	// Stocke le chemin d'accès au fichier 
     
        	openURLForAllLine(pathFile);
        }
        // Used to identify the windows platform.
        private static final String WIN_ID = "Windows";
        // The default system browser under windows.
        private static final String WIN_PATH = "rundll32";
        // The flag to display a url.
        private static final String WIN_FLAG = "url.dll,FileProtocolHandler";
        // The default browser under unix.
        private static final String UNIX_PATH = "netscape";
        // The flag to display a url.
        private static final String UNIX_FLAG = "-remote openURL";
    }
    Je n'ai que de petites connaissances en développement mais ouvert au critique

    Merci à vous,

  2. #2
    Modérateur
    Avatar de joel.drigo
    Homme Profil pro
    Ingénieur R&D - Développeur Java
    Inscrit en
    Septembre 2009
    Messages
    12 430
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur R&D - Développeur Java
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2009
    Messages : 12 430
    Points : 29 131
    Points
    29 131
    Billets dans le blog
    2
    Par défaut
    Salut,

    Déjà au lieu de bidouiller avec des process et des commandes spécifiques, essaye d'utiliser la méthode browse() de la classe Desktop. Pour le freeze, je suppose que ça doit swapper à mort : je ne sais pas si on peut faire quelque chose, à part ne pas ouvrir les 200 URLs en une rafale (200 onglets voire 200 navigateurs ouverts, c'est un peu furieux et probablement qu'on s'y retrouve péniblement).
    L'expression "ça marche pas" ne veut rien dire. Indiquez l'erreur, et/ou les comportements attendus et obtenus, et donnez un Exemple Complet Minimal qui permet de reproduire le problème.
    La plupart des réponses à vos questions sont déjà dans les FAQs ou les Tutoriels, ou peut-être dans une autre discussion : utilisez la recherche interne.
    Des questions sur Java : consultez le Forum Java. Des questions sur l'EDI Eclipse ou la plateforme Eclipse RCP : consultez le Forum Eclipse.
    Une question correctement posée et rédigée et vous aurez plus de chances de réponses adaptées et rapides.
    N'oubliez pas de mettre vos extraits de code entre balises CODE (Voir Mode d'emploi de l'éditeur de messages).
    Nouveau sur le forum ? Consultez Les Règles du Club.

  3. #3
    Membre régulier Avatar de vertebre
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2015
    Messages
    184
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2015
    Messages : 184
    Points : 111
    Points
    111
    Par défaut
    re, je viens de regardé la méthode browse() de la classe desktop, mais si je ne me trompe pas çà me génère un interface graphique pour chercher le fichier, ce que je ne veux pas.

    C'est à dire que j'ai continué ma bidouille, j'ai refait un peu le code et il n'ouvre les url que par intermittence maintenant:

    Classe BroswerControl :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.util.Scanner;
     
    public class BrowserControl implements IFile {
     
    // Méthode qui détermine si l'application est lançé sur un OS un windows ou pas
        public static boolean isWindowsPlatform()
        {
            String os = System.getProperty("os.name");
            if ( os != null && os.startsWith(WIN_ID))
                return true;
            else
                return false;
     
        }
     
    // Fonction qui permet d'écrire dans un fichier
    	public void ecrire(String nomFic, String texte) {
    		//on va chercher le chemin et le nom du fichier et on me tout ça dans un String
    		String adressedufichier = System.getProperty("user.dir") + "/"+ nomFic;
     
    		//on met try si jamais il y a une exception
    		try
    		{
    			/**
                             * BufferedWriter a besoin d un FileWriter, 
                             * les 2 vont ensemble, on donne comme argument le nom du fichier
                             * true signifie qu on ajoute dans le fichier (append), on ne marque pas par dessus 
                             
                             */
    			FileWriter fw = new FileWriter(adressedufichier, true);
     
    			// le BufferedWriter output auquel on donne comme argument le FileWriter fw cree juste au dessus
    			BufferedWriter output = new BufferedWriter(fw);
     
    			//on marque dans le fichier ou plutot dans le BufferedWriter qui sert comme un tampon(stream)
    			output.write(texte);
    			//on peut utiliser plusieurs fois methode write
     
    			output.flush();
    			//ensuite flush envoie dans le fichier, ne pas oublier cette methode pour le BufferedWriter
     
    			output.close();
    			//et on le ferme
    			System.out.println("fichier créé");
    		}
    		catch(IOException ioe){
    			System.out.print("Erreur : ");
    			ioe.printStackTrace();
    			}
     
    	}
     
    // Fonction qui affiche une URL sur Windows ou UNIX
        public static void displayURL(String url)
        {
            boolean windows = isWindowsPlatform();
            String cmd = null;
            try
            {
                if (windows)
                {
                    // cmd = 'rundll32 url.dll,FileProtocolHandler http://...'
                    cmd = WIN_PATH + " " + WIN_FLAG + " " + url;
                    Process p = Runtime.getRuntime().exec(cmd);
                }
                else
                {
                    // Under Unix, Netscape has to be running for the "-remote"
                    // command to work.  So, we try sending the command and
                    // check for an exit value.  If the exit command is 0,
                    // it worked, otherwise we need to start the browser.
                    // cmd = 'netscape -remote openURL(http://www.javaworld.com)'
                    cmd = UNIX_PATH + " " + UNIX_FLAG + "(" + url + ")";
                    Process p = Runtime.getRuntime().exec(cmd);
                    try
                    {
                        // wait for exit code -- if it's 0, command worked,
                        // otherwise we need to start the browser up.
                        int exitCode = p.waitFor();
                        if (exitCode != 0)
                        {
                            // Command failed, start up the browser
                            // cmd = 'netscape http://www.javaworld.com'
                            cmd = UNIX_PATH + " "  + url;
                            p = Runtime.getRuntime().exec(cmd);
                        }
                    }
                    catch(InterruptedException x)
                    {
                        System.err.println("Error bringing up browser, cmd='" +
                                           cmd + "'");
                        System.err.println("Caught: " + x);
                    }
                }
            }
            catch(IOException x)
            {
                // couldn't exec browser
                System.err.println("Could not invoke browser, command=" + cmd);
                System.err.println("Caught: " + x);
            }
        }
     
    // Fonction permettant de lancer firefox
        public static void launchFirefox() {
        	final String CHEMIN = "C:\\My\\Scripts\\";
            try {
            	// On patiente 2 secondes avant d'ouvrir de nouveaux URL
    			try {
    				System.out.println("Pour la fluidité du programme, on lance Mozilla Firefox installé içi:" +CHEMIN + "start_firefox.bat"+"\nPatienter pendant son initialisation ...");
    				Thread.sleep(2000);                 //1000 milliseconds is one second.
    			} catch(InterruptedException ex) {
    			    Thread.currentThread().interrupt();
    			}
                String[] commande = {"cmd.exe", "/C", CHEMIN + "start_firefox.bat"};
                Runtime.getRuntime().exec(commande);
    	            // On patiente 2 secondes
    					try {
    					    Thread.sleep(5000);                 //1000 milliseconds is one second.
    					} catch(InterruptedException ex) {
    					    Thread.currentThread().interrupt();
    					}
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
     
    // Fonction permettant de lire un fichier ligne par ligne et d'afficher les URL contenant http ou https
     	public static void openURLForAllLine(File fileForFileName){
     
    		String urlName="";				// Stocke le nom de l'URL en cours d'affichage
     		// Lire un fichier ligne par ligne
     		try{
     			// Création du flux bufférisé sur un FileReader, immédiatement suivi par un 
     			// try/finally, ce qui permet de ne fermer le flux QUE s'il le reader
     			// est correctement instancié (évite les NullPointerException)
     			BufferedReader buff = new BufferedReader(new FileReader(fileForFileName));
     
     			try {
     			String line;
     			// Lecture du fichier ligne par ligne. Cette boucle se termine
     			// quand la méthode retourne la valeur null.
     
     			String[] urlTab = new String[9];
     			int cpte=9;
    			int indice = 0;
     
    			while (cpte!=0) {
     
    				// Tant qu'il y a des lignes à lire et si http ou https présent comme occurence dans la ligne en cours
    	 			while ((line = buff.readLine()) != null && (line.contains("http") || line.contains("https"))) {
    						// on stocke la ligne dans la variable urlName
    						urlTab[indice]=line;	
     
     
    		 				// On affiche l'URL dans le navigateur
    		 				for (int i=0;i<urlTab.length;i++) {
    								displayURL(urlTab[i]);
    		 				}
     
    		 				// On patiente 5 secondes avant d'ouvrir de nouveaux URL
    		 				try {
    		 				    Thread.sleep(10000);                 //1000 milliseconds is one second.
    		 				} catch(InterruptedException ex) {
    		 				    Thread.currentThread().interrupt();
    		 				}
    	 			}
     			}
     
     			} finally {
     			// dans tous les cas, on ferme nos flux
     			buff.close();
     			}
     			} catch (IOException ioe) {
     			// erreur de fermeture des flux
     			System.out.println("Erreur --" + ioe.toString());
     			}
     
     	}
     
    /* Main principale :
         * Lancement du programme
         * On récupère le dossier que l'utilisateur aura spécifié
         * On récupère le nom du fichier que l'utilisateur aura spécifié
         * On appelle la fonction qui ouvre les URL
         */
        public static void main(String[] args)
        {
        	launchFirefox();
        	Scanner sc = new Scanner(System.in);
     
        	// Demander le dossier du fichier (se termine par un \)
        	 		System.out.println("\nEntrer le nom du dossier où se situe le fichier avec un \\ en fin de chaine");
        	 		java.awt.Toolkit.getDefaultToolkit().beep();
        	 		String pathFolder = sc.nextLine();
        	// Demander le nom du fichier avec son extension
        	 		System.out.println("Entrer le nom du fichier avec son extension");
        	 		java.awt.Toolkit.getDefaultToolkit().beep();
        	 		String fileName = sc.nextLine();
        	 		File pathFile= new File(pathFolder+fileName); 	// Stocke le chemin d'accès au fichier 
     
        	openURLForAllLine(pathFile);
     
     
        }
     
     
     
    }
    Interface IFile :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileReader;
    import java.io.IOException;
     
    public interface IFile {
     
     
    	// Attributs
    		public String pathFolder = "C:\\files\\"; 		// Stocke le chemin d'accès au dossier du fichier
     
    	// Used to identify the windows platform.
    	static final String WIN_ID = "Windows";
    	// The default system browser under windows.
    	static final String WIN_PATH = "rundll32";
    	// The flag to display a url.
    	static final String WIN_FLAG = "url.dll,FileProtocolHandler";
    	// The default browser under unix.
    	static final String UNIX_PATH = "netscape";
    	// The flag to display a url.
    	static final String UNIX_FLAG = "-remote openURL";	
     
     
    	public void ecrire(String nomFic, String texte);
     
    	// Méthode qui détermine si l'application est lançé sur un OS un windows ou pas
        public static boolean isWindowsPlatform()
        {
            String os = System.getProperty("os.name");
            if ( os != null && os.startsWith(WIN_ID))
                return true;
            else
                return false;
     
        }
     
     // Fonction qui affiche une URL sur Windows ou UNIX
        public static void displayURL(String url)
        {
            boolean windows = isWindowsPlatform();
            String cmd = null;
            try
            {
                if (windows)
                {
                    // cmd = 'rundll32 url.dll,FileProtocolHandler http://...'
                    cmd = WIN_PATH + " " + WIN_FLAG + " " + url;
                    Process p = Runtime.getRuntime().exec(cmd);
                }
                else
                {
                    // Under Unix, Netscape has to be running for the "-remote"
                    // command to work.  So, we try sending the command and
                    // check for an exit value.  If the exit command is 0,
                    // it worked, otherwise we need to start the browser.
                    // cmd = 'netscape -remote openURL(http://www.javaworld.com)'
                    cmd = UNIX_PATH + " " + UNIX_FLAG + "(" + url + ")";
                    Process p = Runtime.getRuntime().exec(cmd);
                    try
                    {
                        // wait for exit code -- if it's 0, command worked,
                        // otherwise we need to start the browser up.
                        int exitCode = p.waitFor();
                        if (exitCode != 0)
                        {
                            // Command failed, start up the browser
                            // cmd = 'netscape http://www.javaworld.com'
                            cmd = UNIX_PATH + " "  + url;
                            p = Runtime.getRuntime().exec(cmd);
                        }
                    }
                    catch(InterruptedException x)
                    {
                        System.err.println("Error bringing up browser, cmd='" +
                                           cmd + "'");
                        System.err.println("Caught: " + x);
                    }
                }
            }
            catch(IOException x)
            {
                // couldn't exec browser
                System.err.println("Could not invoke browser, command=" + cmd);
                System.err.println("Caught: " + x);
            }
        }
     
    	// Fonction permettant de lire un fichier ligne par ligne et d'afficher les URL contenant http ou https
    	public static void openURLForAllLine(File fileForFileName){		
     
    			String urlName="";				// Stocke le nom de l'URL en cours d'affichage
    	 		// On crée le 
    	 		// Lire un fichier ligne par ligne
    	 		try{
    	 			// Création du flux bufférisé sur un FileReader, immédiatement suivi par un 
    	 			// try/finally, ce qui permet de ne fermer le flux QUE s'il le reader
    	 			// est correctement instancié (évite les NullPointerException)
    	 			BufferedReader buff = new BufferedReader(new FileReader(fileForFileName));
     
    	 			try {
    	 			String line;
    	 			// Lecture du fichier ligne par ligne. Cette boucle se termine
    	 			// quand la méthode retourne la valeur null.
    	 			while ((line = buff.readLine()) != null) {
    	 				// Condition si http ou https présent comme occurence dans la ligne en cours
    	 				if (line.contains("http") && line.contains("https")) {
    	 					// on stocke la ligne dans la variable urlName
    	 					urlName=line;
    	 					// On affiche l'URL dans le navigateur
    	 					displayURL(urlName);
    	 				}
    	 			}
    	 			} finally {
    	 			// dans tous les cas, on ferme nos flux
    	 			buff.close();
    	 			}
    	 			} catch (IOException ioe) {
    	 			// erreur de fermeture des flux
    	 			System.out.println("Erreur --" + ioe.toString());
    	 			}
     
    	 	}
     
     
    	public static final String CHEMIN = "C:\\My\\Scripts";
    	public static void launchFirefox() {
        	final String CHEMIN = "C:\\My\\Scripts\\";
            try {
            	// On patiente 2 secondes avant d'ouvrir de nouveaux URL
    			try {
    				System.out.println("\nPour la fluidité du programme, on lance Mozilla Firefox installé içi:" +CHEMIN + "start_firefox.bat"+"\nPatienter pendant son initialisation ...");
    			    Thread.sleep(5000);                 //1000 milliseconds is one second.
    			} catch(InterruptedException ex) {
    			    Thread.currentThread().interrupt();
    			}
                String[] commande = {"cmd.exe", "/C", CHEMIN + "start_firefox.bat"};
                Runtime.getRuntime().exec(commande);
    	            // On patiente 2 secondes avant d'ouvrir de nouveaux URL
    					try {
    					    Thread.sleep(5000);                 //1000 milliseconds is one second.
    					} catch(InterruptedException ex) {
    					    Thread.currentThread().interrupt();
    					}
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
     
    }
    Mais en terme de qualité de code, ce n'est pas du tous çà au vue de ta réponse ?

  4. #4
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    Citation Envoyé par vertebre Voir le message
    re, je viens de regardé la méthode browse() de la classe desktop, mais si je ne me trompe pas çà me génère un interface graphique pour chercher le fichier, ce que je ne veux pas.
    Heu ça fait exactement la même chose que ton code, mais en plus stable: ouvrir l'url avec le browser par défaut de l'OS.

  5. #5
    Membre régulier Avatar de vertebre
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2015
    Messages
    184
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2015
    Messages : 184
    Points : 111
    Points
    111
    Par défaut
    ok et bien j'ai mal compris ce que j'ai lu alors.

    Peux tu m'en dire plus sur la stabilité de cette méthode stp ?

  6. #6
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    ben elle fonctionne quel que soit l'os et surtout quel que soit le browser par défaut. Si j'ai chrome sous linux, elle lancera chrome. Si j'ai opera par défaut sous windows, elle lancera opera. Alors que ton code ne marche que sous windows, avec un curieux mélange de rundll, de netscape et de firefox

    Après, je vois pas quel est ton but, parce qu'ouvrir 200 onglets dans un browser, j'en vois pas trop l'intérêt, à part tuer la machine hôte. A 10M l'onglet, tu va lui manger 2G dans le meilleur des cas

  7. #7
    Membre régulier Avatar de vertebre
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2015
    Messages
    184
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2015
    Messages : 184
    Points : 111
    Points
    111
    Par défaut
    ben elle fonctionne quel que soit l'os et surtout quel que soit le browser par défaut. Si j'ai chrome sous linux, elle lancera chrome. Si j'ai opera par défaut sous windows, elle lancera opera.
    C'est noté.

    Après, je vois pas quel est ton but, parce qu'ouvrir 200 onglets dans un browser, j'en vois pas trop l'intérêt, à part tuer la machine hôte. A 10M l'onglet, tu va lui manger 2G dans le meilleur des cas
    Sur ma machine hôte j'ai une pointe à 100% et freeze pendant 12sec, puis pas mal de RAM effectivement.

    Je ne cherchais pas le programme parfait juste pour mes besoins personnels disons que je devais ouvrir beaucoup d'URL pour vérifier que les liens renvoyaient bien sur tel site.
    Chose faite, je n'utiliserai plus mon 1er programme, seulement le 2eme que je vais encore amélioré.

    çà ne m'a pas empêché d'apprendre de nouvelle choses

    Bonne soirée et merci à vous 2

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [Plone] ouverture d'un fichier texte (problème très simple)
    Par Beatrix_debutante dans le forum Zope
    Réponses: 6
    Dernier message: 03/10/2006, 17h12
  2. [VB6] Ouverture de plusieurs fichiers textes
    Par Asdorve dans le forum VB 6 et antérieur
    Réponses: 2
    Dernier message: 12/09/2006, 10h45
  3. Message étrange à l'ouverture d'un fichier texte
    Par Bahan dans le forum Applications et environnements graphiques
    Réponses: 7
    Dernier message: 27/07/2006, 11h16
  4. Réponses: 4
    Dernier message: 21/04/2006, 21h55
  5. [VBA-E] Formatage des données à l'ouverture d'un fichier texte
    Par jmercier dans le forum Macros et VBA Excel
    Réponses: 4
    Dernier message: 30/11/2005, 17h00

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo