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 :

Connaitre le type d'un fichier sans son extension


Sujet :

Entrée/Sortie Java

  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Juillet 2009
    Messages
    24
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2009
    Messages : 24
    Points : 19
    Points
    19
    Par défaut Connaitre le type d'un fichier sans son extension
    bonjour

    j'essaie de connaitre le type d'un fichier sans avoir son extension.

    selon cette page, le meilleur algo de reconnaissance de type est celui d'Aperture.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    private static String getMagicMimeType(File file)
    {
    	try
    	{
    		MagicMimeTypeIdentifier mmti = new MagicMimeTypeIdentifier();
    		FileInputStream fis = new FileInputStream(file);
    		byte[] bytes = new byte[mmti.getMinArrayLength()];
    		fis.read(bytes);
    		return mmti.identify(bytes, file.getName(), null);
    	}
    	catch (FileNotFoundException e) {e.printStackTrace(); return "error";}
    	catch (IOException e) {e.printStackTrace(); return "error";}
    }
    j'utilise ce code trouvé sur la même page.

    ça compile mais j'ai une erreur quand j'essaie de trouver le type du fichier:


    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
     
    Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
            at org.semanticdesktop.aperture.mime.identifier.magic.MagicMimeTypeIdentifier.<init>(MagicMimeTypeIdentifier.java:43)
            at org.semanticdesktop.aperture.mime.identifier.magic.MagicMimeTypeIdentifier.<init>(MagicMimeTypeIdentifier.java:50)
            at javaapplication1.NewApplication.getMagicMimeType(NewApplication.java:525)
            at javaapplication1.NewApplication.openMenuItemActionPerformed(NewApplication.java:544)
            at javaapplication1.NewApplication.access$1200(NewApplication.java:66)
            at javaapplication1.NewApplication$12.actionPerformed(NewApplication.java:329)
            at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
            at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
            at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
            at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
            at javax.swing.AbstractButton.doClick(AbstractButton.java:357)
            at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1225)
            at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1266)
            at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:272)
            at java.awt.Component.processMouseEvent(Component.java:6263)
            at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
            at java.awt.Component.processEvent(Component.java:6028)
            at java.awt.Container.processEvent(Container.java:2041)
            at java.awt.Component.dispatchEventImpl(Component.java:4630)
            at java.awt.Container.dispatchEventImpl(Container.java:2099)
            at java.awt.Component.dispatchEvent(Component.java:4460)
            at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
            at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
            at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
            at java.awt.Container.dispatchEventImpl(Container.java:2085)
            at java.awt.Window.dispatchEventImpl(Window.java:2475)
            at java.awt.Component.dispatchEvent(Component.java:4460)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
            at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
            at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
    Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
            at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
            at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
            at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
            ... 34 more
    j'ai essayé avec les autre librairies (Java Mime Magic, mime-util) mais j'ai à chaque fois des erreurs au lancement du programme...

  2. #2
    Membre régulier
    Profil pro
    Inscrit en
    Novembre 2006
    Messages
    75
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Novembre 2006
    Messages : 75
    Points : 72
    Points
    72
    Par défaut
    Bonjour,

    Ton problème est dû a un jar manquant. C'est celui qui contient la classe org.slf4j.LoggerFactory

    Tu peux la trouver dans ce jar : slf4j-api-1.5.5.jar

    ++@

  3. #3
    Membre à l'essai
    Profil pro
    Inscrit en
    Juillet 2009
    Messages
    24
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2009
    Messages : 24
    Points : 19
    Points
    19
    Par défaut
    Citation Envoyé par redsonic Voir le message
    Bonjour,

    Ton problème est dû a un jar manquant. C'est celui qui contient la classe org.slf4j.LoggerFactory

    Tu peux la trouver dans ce jar : slf4j-api-1.5.5.jar

    ++@
    merci !

    dans ce thread que je viens de découvrir, ils disent de télécharger commons-logging-api.jar

    ça marche aussi ou ton fichier est mieux ?

  4. #4
    Membre à l'essai
    Profil pro
    Inscrit en
    Juillet 2009
    Messages
    24
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2009
    Messages : 24
    Points : 19
    Points
    19
    Par défaut
    maintenant j'ai cette erreur (avec slf4j)

    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
    SLF4J: Class path contains multiple SLF4J bindings.
    SLF4J: Found binding in [jar:file:/C:/Users/Admin/Desktop/%23JAVA/%23MIME/%23Aperture/%23slf4j-1.5.8%20(librairie%20n%c3%a9cessaire)/slf4j-jcl-1.5.8.jar!/org/slf4j/impl/StaticLoggerBinder.class]
    SLF4J: Found binding in [jar:file:/C:/Users/Admin/Desktop/%23JAVA/%23MIME/%23Aperture/%23slf4j-1.5.8%20(librairie%20n%c3%a9cessaire)/slf4j-jdk14-1.5.8.jar!/org/slf4j/impl/StaticLoggerBinder.class]
    SLF4J: Found binding in [jar:file:/C:/Users/Admin/Desktop/%23JAVA/%23MIME/%23Aperture/%23slf4j-1.5.8%20(librairie%20n%c3%a9cessaire)/slf4j-log4j12-1.5.8.jar!/org/slf4j/impl/StaticLoggerBinder.class]
    SLF4J: Found binding in [jar:file:/C:/Users/Admin/Desktop/%23JAVA/%23MIME/%23Aperture/%23slf4j-1.5.8%20(librairie%20n%c3%a9cessaire)/slf4j-nop-1.5.8.jar!/org/slf4j/impl/StaticLoggerBinder.class]
    SLF4J: Found binding in [jar:file:/C:/Users/Admin/Desktop/%23JAVA/%23MIME/%23Aperture/%23slf4j-1.5.8%20(librairie%20n%c3%a9cessaire)/slf4j-simple-1.5.8.jar!/org/slf4j/impl/StaticLoggerBinder.class]
    SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
    Exception in thread "AWT-EventQueue-0" java.lang.StackOverflowError
            at java.lang.reflect.Method.<init>(Method.java:116)
            at java.lang.reflect.Method.copy(Method.java:143)
            at java.lang.reflect.ReflectAccess.copyMethod(ReflectAccess.java:118)
            at sun.reflect.ReflectionFactory.copyMethod(ReflectionFactory.java:282)
            at java.lang.Class.searchMethods(Class.java:2656)
            at java.lang.Class.getMethod0(Class.java:2670)
            at java.lang.Class.getMethod(Class.java:1603)
            at org.apache.commons.logging.LogFactory.getContextClassLoader(LogFactory.java:438)
            at org.apache.commons.logging.LogFactory$1.run(LogFactory.java:222)
            at java.security.AccessController.doPrivileged(Native Method)
            at org.apache.commons.logging.LogFactory.getFactory(LogFactory.java:218)
            at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:370)
            at org.slf4j.impl.JCLLoggerFactory.getLogger(JCLLoggerFactory.java:69)
            at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:243)
            at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:155)

  5. #5
    Membre expérimenté
    Profil pro
    Inscrit en
    Septembre 2006
    Messages
    1 466
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2006
    Messages : 1 466
    Points : 1 610
    Points
    1 610
    Par défaut
    Hello,
    Utilise un seul de ces jar pour voir.

  6. #6
    Expert confirmé
    Avatar de le y@m's
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Février 2005
    Messages
    2 636
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Février 2005
    Messages : 2 636
    Points : 5 943
    Points
    5 943
    Par défaut
    Pour info il existe également les méthodes standards suivante :
    Par contre je n'ai aucune idée du pourcentage de réussite.
    Je ne répondrai à aucune question technique par MP.

    Pensez aux Tutoriels et aux FAQs avant de poster (pour le java il y a aussi JavaSearch), n'oubliez pas non plus la fonction Rechercher.
    Enfin, quand une solution a été trouvée à votre problème
    pensez au tag

    Cours Dvp : http://ydisanto.developpez.com
    Blog : http://yann-disanto.blogspot.com/
    Page perso : http://yann-disanto.fr

Discussions similaires

  1. Récuperer le nom d'un fichier sans son extension
    Par tidusff10 dans le forum Général Python
    Réponses: 7
    Dernier message: 24/02/2012, 17h40
  2. [SP-2010] Recupérer le nom d'un fichier sans son extension
    Par supierre dans le forum Développement Sharepoint
    Réponses: 4
    Dernier message: 31/01/2012, 15h33
  3. connaitre le type d'un fichier sans extension
    Par Atasuke dans le forum C
    Réponses: 5
    Dernier message: 07/11/2011, 16h56
  4. Obtenir le nom d'un fichier sans son extension
    Par verso61 dans le forum VB.NET
    Réponses: 5
    Dernier message: 28/10/2010, 13h46
  5. Récupérer le nom d'un fichier sans son extension
    Par Shoot dans le forum Langage
    Réponses: 5
    Dernier message: 09/04/2008, 09h32

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