How To Get FileType and MIME Type from a File

Hi,
I am using following ways to get FileType and MIME Type.
I am able to get file type, but I am getting MIME Type as */*
Can any one please let me know how to get MIME Type, but it should not be time consuming process.
For File Type I am using following Code:
private String getFileData(InputStream inStream) {
fileName = C:\temp\temp.tiff
String filePath = Util.createTempFile(fileName);
RandomAccessFile raf = new RandomAccessFile(filePath, "rw");
while (inStream.available() > 0) {
     byte[] buf = new byte[inStream.available()];
     inStream.read(buf);
     raf.write(buf);
inStream.close();
raf.close();
File file = new File(filePath);
JFileChooser chooser = new JFileChooser();
String fileType = chooser.getTypeDescription(file);
file.delete();
//MIME Type I am getting from
DataHandler data = new DataHandler(new DocumentSource(inStream));
data.getContentType();
data.getContentType() is not working well in all cases.
Can any one help me on this.
Thanks in advance,
Ram.
Edited by: javausers07 on Apr 15, 2009 4:25 PM

javausers07 wrote:
Hi,
I am using following ways to get FileType and MIME Type.
I am able to get file type, but I am getting MIME Type as */*
Can any one please let me know how to get MIME Type, but it should not be time consuming process.
For File Type I am using following Code:
private String getFileData(InputStream inStream) {
fileName = C:\temp\temp.tiff
String filePath = Util.createTempFile(fileName);
RandomAccessFile raf = new RandomAccessFile(filePath, "rw");
while (inStream.available() > 0) {
     byte[] buf = new byte[inStream.available()];
     inStream.read(buf);
     raf.write(buf);
inStream.close();
raf.close();
File file = new File(filePath);Why do you do all above?
JFileChooser chooser = new JFileChooser();
String fileType = chooser.getTypeDescription(file);
file.delete();
//MIME Type I am getting from
DataHandler data = new DataHandler(new DocumentSource(inStream));
data.getContentType();
data.getContentType() is not working well in all cases.That's because there's no way to get MIME type of all files on all filesystems.
Kaj

Similar Messages

  • How to extract text and image information from postscript file

    I want to write a programe,and extract text and image information from postscript file using Java.Is it possible? How to extract ?
    Thank!

    First of all, PostScript is not a "text" file. It can and often does contain binary data. Since PostScript streams often contain nested procedures, unless you process the procedure definitions and can "execute" them, you cannot simply "scan" a file to get what you want. No, I can't talk about this in detail since it is quite complex. But Adobe does have the
    PostScript Language Reference Manual on-line for download at
    . Look that over and you will have a fairly healthy respect as to the task involved.
    - Dov

  • How to get WIDTH and HEIGHT fields from applet tag?

    I am developing an applet using JDK1.1 (to ensure microsoft jvm compatability).
    A problem I'm facing is that there are no getWidth() or getHeight() method for Applet in 1.1, so I am hoping I can get this info from my html: <APPLET CODE="MyApplet" WIDTH=600 HEIGHT=856></APPLET>
    getParameter didn't work, so does anyone have any ideas how I could get the width and height?
    Cheers,
    James

    Write a jpeg decoder that can figure out how to determine the width/height of a jpeg file? Google it.
    Or if you're really lazy, load each jpeg using the
    Toolkit.loadImage( URL ) function and use getWidth/getHeight from there, but that's slow.

  • How to get Driver and url names from a connection pool

    Hi,
    How to get the DriverName and URL from an existing pool, If I know the name of
    connection pool ? Is it possible to know the name of related pool , if I know
    the name of datasource?
    Thx
    Manish

    hi
    there are 2 ways:
    url must be: jdbc:weblogic:pool[:connectionPoolID]
    or
    jdbc:weblogic:jts[:connectionPoolID] (if you want to use jts with your JDBC connection.)
    see http://e-docs.bea.com/wls/docs60//javadocs/weblogic/jdbc/pool/Driver.html
    However, I think it is safer to configure and use DataSource to get connection.
    Nicolas
    "kumar" <[email protected]> wrote:
    >
    Hi,
    How to get the DriverName and URL from an existing pool, If I know the name
    of
    connection pool ? Is it possible to know the name of related pool , if I
    know
    the name of datasource?
    Thx
    Manish

  • How to get aperture3 and iPhoto to process RAW files from NEX7 ?

    I have read that there is an update which fixes aperture3 and iPhoto to process RAW files from  sony NEX7. How do I find and download this Update ?

    Look throught http://www.apple.com/support/downloads and you'll find this
    http://support.apple.com/kb/DL1510
    Regards
    TD

  • How to get contacts and calendar info from my old palm files

    I used to use a Palm Tungsten T3. I no longer have it but until recently I still used the Palm Desktop. My computer "died" and I was able to copy all the Palm files of of it but now I have no idea how to get the contact and calendar(less important than contacts) info in some form I can use. I do not currently have any Palm software installed on my computer. I have Microsoft Windows XP on my computer now and use Outlook or Outlook Express. Does anyone have any advice for me. Thanks in advance.
    Post relates to: Tungsten T3

    I'm having the same problem.  Desktop 4.1.4 on old PC.  New PC with Win 7.   Loaded 6.2 and when I went to Import 6.2 is looking for .aba files.  Old PC has all .dat files.  How do I import or transfer addresses and other contact info to new PC??  Thanks.

  • How to get the pull path name from a file upload window

    Hello everyone!
    I have encountered the following problem with the following JSP code:
    <form method="post" action="filename.jsp">
    Upload JAVA program:
    <input type=file size=20 name="fname" accept="java">
    <input type=submit value="go">
    </form>
    <%
    String s = "";
    if (request.getParameter("fname") != null)
    s = request.getParameter("fname")
    %>
    The value of s is alway the filename. However I want to get the full path in addition to the filename, so that I can read the file. Does anyone know how to get the pull name of the file?
    thanks a lot in advance,

    Dear Sir,
    thanks a lot for your reply. Please let me explain what I intended to do: I want to upload a file from the local machine and then read the content of the file. Therefore I need to the fullpath of the filename like /var/local/file.java instead of file.java. The latter is what I got.
    The problem I have with your code is that the function like "request.getServerScheme()" is not recognized. Maybe is it because I didn't install servelet package? I only installed javax package btw. Also my application runns on Tomcat server if this could give you some information. The error message I had is as follows:
    org.apache.jasper.JasperException: Unable to compile class for JSP
    An error occurred at line: 36 in the jsp file: /addExercise.jsp
    Generated servlet error:
    [javac] Compiling 1 source file
    /usr/local/jakarta-tomcat-5.0.12/work/Catalina/localhost/tutor/org/apache/jsp/addExercise_jsp.java:133: cannot resolve symbol
    symbol : method getServerScheme ()
    location: interface javax.servlet.http.HttpServletRequest
    url = request.getServerScheme()
    ^
    An error occurred at line: 36 in the jsp file: /addExercise.jsp
    Generated servlet error:
    /usr/local/jakarta-tomcat-5.0.12/work/Catalina/localhost/tutor/org/apache/jsp/addExercise_jsp.java:136: cannot resolve symbol
    symbol : method getServerScheme ()
    location: interface javax.servlet.http.HttpServletRequest
    + ((("http".equals(request.getServerScheme()) && request.getServerPort() != 80)
    ^
    An error occurred at line: 36 in the jsp file: /addExercise.jsp
    Generated servlet error:
    /usr/local/jakarta-tomcat-5.0.12/work/Catalina/localhost/tutor/org/apache/jsp/addExercise_jsp.java:137: cannot resolve symbol
    symbol : method getServerScheme ()
    location: interface javax.servlet.http.HttpServletRequest
    ||("https".equals(request.getServerScheme()) && request.getServerPort() != 443))
    ^
    An error occurred at line: 36 in the jsp file: /addExercise.jsp
    Generated servlet error:
    /usr/local/jakarta-tomcat-5.0.12/work/Catalina/localhost/tutor/org/apache/jsp/addExercise_jsp.java:139: cannot resolve symbol
    symbol : method getServletConfig ()
    location: interface javax.servlet.http.HttpServletRequest
    + "/" + request.getServletConfig().getServletName()
    ^
    An error occurred at line: 36 in the jsp file: /addExercise.jsp
    Generated servlet error:
    /usr/local/jakarta-tomcat-5.0.12/work/Catalina/localhost/tutor/org/apache/jsp/addExercise_jsp.java:140: cannot resolve symbol
    symbol : variable path
    location: class org.apache.jsp.addExercise_jsp
    + "/" + path
    ^
    5 errors
         org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:128)
         org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:351)
         org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:413)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:453)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:437)
         org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:555)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:291)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

  • How to know date and time information from Trace File defaultTrace.X.trc?

    Hi, all.
      i'm using EP 6.0 SP9 patch 1.
      As you know, default trace is written in the <SID>\JC00\j2ee\cluster\server0\log\defaultTrace.X.trc.
      By using the default trace formatter, it shows like the following sample messages.
    #1.5#0011110E7B2000590000000100000A100003EC71562E6EBC#1104396451585#com.sap.jms.server.ServerClientAdapter##com.sap.jms.server.ServerClientAdapter#Guest#18####716257115a3f11d9b73b0011110e7b20#SAPEngine_Application_Thread[impl:3]_23##0#0#Error#1#/Applications/JMS#Plain###JMS internal error at ServerClientAdapter! JMS Service is not started!#
      My questions are
      1. how do we retrieve the date and time information from the above message? It seems that this message has date and time info because LogViewer shows the date and time based on the above message.
      2. how do we change the above date format to easier one
    like "YYYY:MM:DD:hh:mm:ss"? i know that it can be configured from the Visual Admin --> Services --> Log Configurator but i don't know the exact place for the trace file.
      Thanks.

    Hi Sejoon,
    I use the standalone Logviewer to read the log files. Works great.
    "If you have an SAP Web Application Server Java 6.20 or below you may also get a standalone_logviewer.zip file at the SAP Service Marketplace at service.sap.com/download &#8594; SAP NetWeaver &#8594; Release ‘04. In this case JDK version 1.3 or higher must be installed on the system. The java version must be same on the server and the client.
    In the SAP Web AS Java 6.30 installation a folder named logviewer_standalone can be found under: <path Of J2EE installation>/<SysID>/JC<nr>/j2ee/admin/logviewer_standalone. Verify that the batch file logviewer.bat is installed in the directory logviewer-standalone.
    (source -> http://help.sap.com/saphelp_nw04/helpdata/en/e4/540c404a435509e10000000a1550b0/frameset.htm)
    Best wishes,
    Noel

  • How to get width and height of a jpg file ?

    Hello,
    I'm trying to insert a jpg file in a blob field on my database. The problem is that I need to get the file width and height in pixels. My class does not have a graphic interface, it's a batch. Does anybody has an idea of how can I do that ?
    tia.

    Write a jpeg decoder that can figure out how to determine the width/height of a jpeg file? Google it.
    Or if you're really lazy, load each jpeg using the
    Toolkit.loadImage( URL ) function and use getWidth/getHeight from there, but that's slow.

  • How to get total number of pages from .doc file without using Office interop?

    Hi,
    Kindly help me in getting the total number of pages from a .doc file not .docx file using C#. I know how to get by using Office interop but I do not want to use Office interop.
    So, without office automation in C# let me know how to get the total number of pages from a .doc file.
    Regards,
    Ashok

    Hi Ashok,
    >> I know how to get by using Office interop but I do not want to use Office interop
    Could you tell us why you don't want to use Office interop?
    As far as I know, this is the easiest way to achieve.Hmmm,this is my answer
    http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.pagenumbers.startingnumber(v=office.14).aspx
    Best regards,
    Kristin
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How to get Essential and additional qualifications ,From which table

    Hi all,
    In one of my requirement, the report should show the Qualifications and Essential qualifications columns in the output.
    Requirement is :
    1. I have brought qualifications of Applicant from PB0024 table.
    2. I need to compare these with the Qualifications maintained in Job for the pernr.
    3. There are two types of Qualifications namely essential Qualifications and additional Qualifications.
    4.
    How do we get the Qualifications maintained for a job/Position?
    How can we distinguish between Qualifications and essential Qualifications maintained for a job at the database table level ?
    Please reply ASAP.
    Regards,
    Rama.P

    Hi Dilek Ersoz Adak,
    How can we get the jobs assigned to a position ,from which table ?
    Actually i am doing a custom recruitment report which displayes several fields along with the qualificaions and additional qualifications.
    For the two fileds: in the spec it is given as:
    14.     Qualification (This is maintained in HRPE_PROFQ_TBJID-infotype 0024 of the employee. Thus, check Position maintained for the employee in P4002_OBJID, against this position check for Essential Qualification, related object type u2018Qu2019 HRPE_PROFQ_ESSENTIAL, compare this with the qualifications maintained for the employee in Infotype 0024, and display wherever these maintained.)
    15.     Additional Qualification (This is maintained in HRPE_PROFQ_TBJID-infotype 0024 of the employee. Thus, check Position maintained for the employee in P4002_OBJID, against this position check for Essential Qualification, related object type u2018Qu2019, compare this with the qualifications maintained for the employee in Infotype 0024, and display all qualifications for which HRPE_PROFQ_ESSENTIAL is not maintained.)
    16.     Proficiency (HRPE_PROFQ_PROFC_TEXT)
    in clear :
    1.       Positions (Object Type S) are linked to Job through relationship A 007
    2.       In APDISCOM scenario, Qualifications (Object Type Q) are attached to Object u2018Jobu2019 (Object Type C) through Transaction Code PPPM
    3.       Now, for a Job there can two types of qualifications maintained Essential Qualifications (ii) Additional Qualifications
    4.       For essential qualifications: Against a Qualification we can maintain u201Cessential check boxu201D HRPE_PROFQ
    5.       For additional qualifications: Those qualifications for which HRPE_PROFQ is not maintained
    6.       Now, for an applicant, Qualifications are maintained in Infotype 0024, wherein the necessary qualifications would be selected.
    7.       In the report for field of u201Cessential qualificationu201D, check for qualifications maintained in Infotype 0024 and compare it with qualifications maintained in Job (through Position assigned to the applicant in P4002_OBJID)
    8.       Check for essential qualification HRPE_PROFQ maintained in Job and check whether the same Q is maintained in Infotype 0024 for the applicant, if yes, then generated Text of the Q
    9.       If there are any additional qualifications which are maintained in the job and not maintained in Infotype 0024, DONu2019T GENERATE ANYTHING IN FIELD
    10.   If there are any additional qualifications which are maintained in the job and if same are maintained in Infotype 0024, generate Q text under field of u201CAdditional Qualificationsu201D in the report
    11.   If there are any extra qualifications in infotype 0024, which are not maintained in Job, then generate Q text under field of u201CAdditional Qualificationsu201D in the report
    Please provide the procedure.(For clarity copy and paste the text in a MS-word)
    Please reply ASAP.
    Regards,
    Rama.P
    Edited by: Rama Chary on Dec 9, 2009 1:28 AM

  • How to get UUTPassed and UUTFailed count from C# ActiveX control

    Hello,
    My operator interface uses TestStand ActiveX control in C#. I will use the OP to test a bench of DUTs, which runs the same sequence file. I would like to know the total UUT-Tested, UUTPassed and UUTFailed count after each DUT tested. Is there any embedded parameter does the job for me and how could I get it? If there is not, I have to create internal variables in C# to do the job.
    Thanks
    Regards,
    Solved!
    Go to Solution.

    No, there is no build in function for this. So either you will have to implement something like this in on of the following:
    a) The user interface
    b) The SequenceFile (as long as it is not unloaded in between)
    c) The process model
    d) Use an external tool for analysis
    If you are already working with databases for reporting, i would suggest using d). If not, you can choose. But modifying the process model is not recommended (if other, simple solutions are available), i wouldn't recommend c).
    hope this helps,
    Norbert
    CEO: What exactly is stopping us from doing this?
    Expert: Geometry
    Marketing Manager: Just ignore it.

  • How to get Cube and Dimension ID from SSAS Database programatically

    Hi All,
    I am processing one SSAS cube from SSIS package and processing the cubes dynamically .For this am putting the Cube ID ,Cube name, Dimension ID, Dimension Name in a table and generating the XML programmatically.
     I can right click the properties of the dimension and cube and will get the ID information. But is there any way we can get the ID information programmatically .So that On the fly I will get the information and create the XML without storing
    the these information in table.
    We are using 2008 R2
    Thanks in advance
    Roshan

    Hi,
    Here is the C# code you want. Try it and see.
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Xml;
    using AMO = Microsoft.AnalysisServices;
    namespace ConsoleApplication4
    class Program
    static void Main(string[] args)
    AMO.Server oServer = new AMO.Server();
    oServer.Connect(@"Provider=MSOLAP.5;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=AdventureWorksDW;Data Source=DEVWKS6\MSSQLSERVERMDX");
    foreach (AMO.Database db in oServer.Databases)
    foreach (AMO.Cube cube in db.Cubes)
    Console.WriteLine(System.String.Format("Cube Name : {0} Cube ID : {1}", cube.Name, cube.ID));
    foreach (AMO.CubeDimension dim in cube.Dimensions)
    Console.WriteLine(System.String.Format("Dimension Name : {0} Dimension ID : {1}", dim.Name, dim.ID));
    System.Console.WriteLine("");
    System.Console.WriteLine("");
    oServer.Disconnect(true);
    oServer.Dispose();
    System.Console.ReadLine();
    If you know your target SSAS Database Name, then you could use LINQ to narrow your search. Take a look into the following Code.
    AMO.Database db = oServer.Databases.Cast<AMO.Database>().Where<AMO.Database>(SSASdb => SSASdb.Name == "AdventureWorksDW").FirstOrDefault();
    foreach (AMO.Cube cube in db.Cubes)
    Console.WriteLine(System.String.Format("Cube Name : {0} Cube ID : {1}", cube.Name, cube.ID));
    foreach (AMO.CubeDimension dim in cube.Dimensions)
    Console.WriteLine(System.String.Format("Dimension Name : {0} Dimension ID : {1}", dim.Name, dim.ID));
    System.Console.WriteLine("");
    Best Regards...
    Chandima Lakmal Fonseka

  • How to get workbook and folder list from backend

    Hi,
    I want a list of workbook and their respective folders in excel. How can we find out this from backend?
    Thanks ,
    Sam

    Hi,
    You can try this:
    select d.doc_name,
    d.doc_developer_key,
    x.ex_to_par_name,
    e.exp_name,
    b.ba_name
    from eul10g_us.eul5_documents d,
    eul_us.eul5_elem_xrefs x,
    eul_us.eul5_expressions e,
    eul_us.eul5_ba_obj_links o,
    eul_us.eul5_bas b
    where x.ex_from_type = 'DOC'
    and x.ex_from_id = d.doc_id
    and x.ex_to_id = e.exp_id
    and e.it_obj_id = o.bol_obj_id(+)
    and o.bol_ba_id = b.ba_id(+)Tamir

  • How to get the entire MIME message from a  BodyPart?

    Hi there,
    I am new to javaMail and quite lost with its way of working.
    I have a tool that creates SMIME stuff that needs to be put into MIME envelopes. In the same time I have to manage parsing of simple MIME messages.
    My current problem is the following:
    I have a BodyPart and I am testing if it is SMIME or not (with checks on the ContentType). If it is, then I want to retrieve the entire MIME message (I mean, the the whole text stuff with the headers and the -possibly- encoded64 content) as a String or a byte[]. But I haven't found anything in BodyPart that returns such a thing (everything is about the content). There might be writeTo() but it gives need an output stream that if piped in a pipedinputstream results in a dead lock...
    Help please!!
    Lionel

    hai
    i think you can use the methods in the MimeMessage to get the headers of the message
    by using any one the following
    1) getAllHeaders() use the enumeartion concept and then get the values for the headers using the getHeader(enum.getNextElements())
    2) or use the specific methods such as
    getFrom()
    getAllRecepients()
    getContentType()
    3) getHeader(string headername)
    bye

Maybe you are looking for

  • A list of values type item in a based table block

    My block is based on a table. An item of the block take the value of a field of the table when the form raises. But this item must be updateable (by selecting a value in a list) and then it must be of the list of value type. And the values in the lis

  • How to solve page flickering in a jsp page for chat

    Hi, I'm trying to build a very simple chat application. I'm using JSP as the frontend. The problem is that when I want to refresh the messages typed and list of users currently logged in, the page is refreshing using html refresh tag. The result is v

  • I cleaned whe keys on my macbook and now some keys stopped responding

    I cleaned my keyboard with a wipe and now everytime I press the "t" and "g," either it will not respond or it will give me a random set of random leeqrtwers letters (LIKE This!!) IOU asƒ©˙∆˚¬∆˚¬ Please help.!!

  • How can I get Audio Lock to work?

    In iMovie 4, I lock an audio track to a clip in the Timeline. But, when I increase the duration of a clip that precedes the clips with audios that I've locked to them, the clips shift for the increased duration, but the audio tracks don't stay with t

  • Problem in create cubes?

    Can any one help me to know, what are all the issues will occur the whole database will convert into a SSAS cube ?