Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 30-07-2009
Member
 
Join Date: May 2008
Posts: 255
How is it possible to get the file type in Java?

Hi,

I am trying to get the output on the screen to see the list of files & its properties but no success. I hope someone could help me out.
I tried JAVA SWT but no success yet.
How is it possible to get the file type in Java?

Thanks for the help in advance.
Reply With Quote
  #2  
Old 30-07-2009
Member
 
Join Date: May 2008
Posts: 33
Re: How is it possible to get the file type in Java?

Uses of Class - java.io.File

JFileChooser.getTypeDescription(File f)
Returns the file type.

This is what you need.

http://java.sun.com/j2se/1.4.2/docs/...-use/File.html

I hope this helps you.
Reply With Quote
  #3  
Old 30-07-2009
Member
 
Join Date: May 2008
Posts: 22
Re: How is it possible to get the file type in Java?

Getting the File-Type Name of a File

Files and directories have a type, usually based on their extension. This example retrieves the name of the file type. Examples of file-type names include Java Source and Shortcut. This name is displayed with the filename in a file chooser dialog.

Code:
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);
    // Text Document
Hope this explains.
Reply With Quote
  #4  
Old 30-07-2009
Member
 
Join Date: May 2008
Posts: 32
Re: How is it possible to get the file type in Java?

code of GetFileType .java

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.

Code:
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);
    }
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How is it possible to get the file type in Java?"
Thread Thread Starter Forum Replies Last Post
Content Type | Mime Type for Office 2010 file format and extension ramsun Tips & Tweaks 1 16-08-2010 05:25 PM
Content Type | Mime Type for Office 2007 file format and extension D_chapple Tips & Tweaks 1 16-08-2010 04:44 PM
Implement the return type in java Captain Carrot Software Development 4 25-03-2010 01:34 PM
Type Casting in Java Aakarshan.d Software Development 5 21-01-2010 02:56 PM
File Type / File Folder Options Problem blackz Windows XP Support 2 30-06-2008 03:24 PM


All times are GMT +5.5. The time now is 01:26 AM.