Getting the File-Type Name of a File - Java File Path IO

Java examples for File Path IO:File Attribute

Description

Getting the File-Type Name of a File

Demo Code

import java.io.File;

import javax.swing.JFileChooser;

public class Main {
  public static void main(String[] argv) {
    JFileChooser chooser = new JFileChooser();

    // Create a File instance of the file
    File file = new File("filename.txt");

    // Get the file type name
    String fileTypeName = chooser.getTypeDescription(file);
    System.out.println(fileTypeName);
    // Text Document
  }//from  w  w w  .  j  a  v a 2s  . c o  m
}

Related Tutorials