Java 7: Déterminer le type de contenu d’un fichier

Author:

 int,string,char,static, url, socket, url, socket, java
{filelink=23}


package java7exemples;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class ContenuFichiers
{
 public static void main(String[] args) throws Exception
               {
                 displayContentType("c:/test.txt");  // text/plain
                 displayContentType("c:/lders.dll"); // application/x-msdownload
                 displayContentType("c:/test.doc"); // application/msword
                 displayContentType("c:/java.gif"); // image/gif
               }
 // Afficher le type de contenu de fichier passé en paramètre
static void displayContentType(String pathText) throws Exception
          {
              Path path = Paths.get(pathText);
              String type = Files.probeContentType(path);
              System.out.println(type);
        }
}

Leave a Reply

Your email address will not be published. Required fields are marked *