Home Java Java-get-example Java get File Type



Java get File Type
Posted on: November 6, 2008 at 12:00 AM
This section illustrates you how to get the file type. In the given example, we have create an instance of the class File and passed the file 'Hello.txt' to the constructor of this class.

Java get File Type

     

This section illustrates you how to get the file type. In the given example, we have create an instance of the class File and passed the file 'Hello.txt' to the constructor of this class. The method chooser.getTypeDescription(file) of class JFileChooser returns the file type.

 

 

 

Here is the code of GetFileType .java

import java.io.*;
import javax.swing.*;

class GetFileType {
  public static void main(String[] args){
    JFileChooser chooser = new JFileChooser();
  File file = new File("Hello.txt");
  
  String fileTypeName = chooser.getTypeDescription(file);
  System.out.println("File Type= "+fileTypeName);
  }
}

Output will be displayed as:

Download Source Code

Related Tags for Java get File Type:
cfileclassscriptconstructoriostructmethodsedgettypeconstipreturninstancethisoocreateechotxtexampletoexamjfilechooserssedescriptioneilttydessectionpeceinpassasstagettypemtrososjclesmehowrateratestorxaxampsurntypedctorfilechooseratishellohallivmpleaandconsstrxtttscrssriripthavsthelloctofilechoosepleplndono


More Tutorials from this section

Ask Questions?    Discuss: Java get File Type  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.