How to read File Header in JAVA

I wanna upload a(doc/pdf) file from client site, where I hv to check whether the the file is originally a doc/pdf file or not, I mean not just the extension, but the actual header information of the file. Please some body help me to do this, I dont know how to read the file header. Thnx in advnc.

You can always try looking at the [Header Signatures|http://www.techpathways.com/uploads/headersig.txt]. But it would probably be easier to adjust your application so it doesn't have to guess.
~

Similar Messages

  • How to read file header/open filein binary mode

    i am using FileConnenction API to read from a file. how can i open a file in binary mode so that i can read file header. In other words i want to open a file in binary mode.

    You can always try looking at the [Header Signatures|http://www.techpathways.com/uploads/headersig.txt]. But it would probably be easier to adjust your application so it doesn't have to guess.
    ~

  • [Urgent] How to read files from different directories?

    I am new to Java Programming, I would like to know how to read files from directories other than the current one? (example as follows)
    ProjectDirectory
    |--MainDirectory
    |--MainProgram.java
    |--SupplementDirectory
    |--SupplementProgram.java
    |--Pictures
    |--Image.gif
    What should I write in the MainProgram.java so that I can use the supplementProgram.java from MainProgram and read the Image.gif file from the MainProgram.java?
    Thanks

    Run through the I/O tutorial here. It should get you up to speed on this sort of thing...

  • How to read system eventlog using java program in windows?

    How to read system eventlog using java program in windows?
    is there any java class available to do this ? or any one having sample code for this?
    Your friend Zoe

    Hi,
    There is no java class for reading event log in windows, so we can do one thing we can use windows system 32 VBS script to read the system log .
    The output of this command can be read using java program....
    we can use java exec for executing this system32 vbs script.
    use the below program and pass the command "eventquery"
    plz refer cscript,wscript
    import java.io.*;
    public class CmdExec {
    public static void main(String argv[]) {
    try {
    String line;
    Process p = Runtime.getRuntime().exec("Command");
    BufferedReader input =
    new BufferedReader
    (new InputStreamReader(p.getInputStream()));
    while ((line = input.readLine()) != null) {
    System.out.println(line);
    input.close();
    catch (Exception err) {
    err.printStackTrace();
    This sample program will list all the system log information....
    Zoe

  • How to read system evenlog using java program in windows

    How to read system evenlog using java program in windows???
    is there any java class available to do this ? or any one having sample code for this?
    Your friend Zoe

    Welcome to the Sun forums.
    >
    How to read system evenlog using java program in windows???>
    JNI. (No.)
    >
    is there any java class available to do this ? or any one having sample code for this?>You will generally get better help around here if you read the documentation, try some sample code and come back with a specific question (hopefully with an SSCCE included).
    >
    Your friend Zoe>(raised eyebrow) Thank you for sharing that with us.
    Note also that one '?' denotes a question, while 2 or more generally denotes a dweeb.

  • Vc++ how to read column header of cursor

    How to fetch the Column name or header of the stored procedure which is using a cursor as the output.
    P_out  out sys_refcursor
    need to read the column name of this output.
    I am using Vc++ code to reterive the data, in Vc++ how to read column header of cursor

    You haven't provided much detail to go on.  How are you reading data from the ref cursor? Do you already have a reader from it?
    Maybe this helps.
    Greg
    create or replace procedure proc1 (v1 out sys_refcursor) as
    begin
    open v1 for select * from emp;
    end;
    using System;
    using System.Data;
    using Oracle.DataAccess.Client;
    using Oracle.DataAccess.Types;
    public class RefCur
        public static void Main()
            using (OracleConnection con = new OracleConnection("user id=scott;password=tiger;data source=orcl"))
                con.Open();
                using (OracleCommand cmd = new OracleCommand("proc1", con))
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new OracleParameter("v1", OracleDbType.RefCursor, ParameterDirection.Output));
                    cmd.ExecuteNonQuery();
                    using (OracleDataReader reader = ((OracleRefCursor)cmd.Parameters[0].Value).GetDataReader())
                        for (int i=0;i<reader.FieldCount;i++)
                            Console.WriteLine(reader.GetName(i));

  • How to read the header of an FLV 1.1 file?

    I would like to read the header of an FLV file and determine
    if it's an FLV 1.1 file, and if so, get it's length. (Without
    downloading the entire file. ) How do I do this?

    bump

  • How to read files on server from a java program?

    Hello,
    I am fairly new to JSP programming. I have an issue with reading files. I am trying to call method of a normal java file from a jsp program. The method I am trying to call does some IO operation on Files. I have the files in the same directory as my class files on server that is in WEB-INF/classes folder. In my java program, I am giving just the file name to open because the files and the classes are in the same directory. But this is not working.
    What exactly should I do to read a file from a java program, that is running on the server?
    Any help is appreciated.
    Thanks,
    Krishna

    String realFilePath = application.getRealPath("/WEB-INF/myFile.txt");
    File fileToOpen = new File(realFilePath);
    out.println(fileToOpen.getAbsolutePath() + ": exists? " + fileToOpen.exists());in this case "application" is a reference to the ServletContext.
    It is an implicit variable in a JSP. In a servlet:
    ServletContext application = getServletConfig().getServletContext();

  • How to read file from remote machine

    Hello,
    Hi, i would like to know how to read text file from remote machine using java source code, any code ?
    Thanks very much;
    Best regards
    Kim

    On the server, perform the following steps:
    Parse the request and determine the file to serve
    Open a FileInputStream to the appropriate file
    Obtain a reference to the Servlet OutputStream
    Pipe the bytes from the file to the output stream
    Flush and close the streamYou might want to call HttpServletResponse.setContentType("application/octet") to indicate to the browser that a file download will be occurring. Do so before getting the reference to the Servlet's OutputStream.
    - Saish

  • How to read files....plzzz

    Hi! All,
    I have a problem in reading files using jfilechooser class.
    when i select open menuitem from the file menu and reading it through
    the file reader class it is giving nullpointer exception.
    Also i tried by hardcoding filename in filereader class instead of using getSelectedfile().This time it is not giving null pointer exception but it is showing any stuff.
    Here's the code i am using...
    int returnVal = fc.showOpenDialog(openpanel);
    if(returnVal == JFileChooser.APPROVE_OPTION){
    file = fc.getSelectedFile();
                   //This is where a real application would open the file.
    if(fc == null)
         file = new File("D:\\karthik\\java\\");
         file = new File("D:\\karthik\\java\\kar.txt");
         fc.setCurrentDirectory(file);
    BufferedReader infile = new BufferedReader(new FileReader(file));
         files.append(infile.readline()); //files is the textarea..

    how come you do a fc.setCurrentDirectory(file);?
    where exactly do you get the NullPointerException? what does your stacktrace say?
    thomas

  • How to read file on demand (or) avoid polling in bpel 11g?

    Hello -
    Scenario - Receive two files(A & B) which should end up in two tables (Header, Lines)
    BPEL process -
    1) Receive acitivity - To Read file (A) via File adapter
    2) Tranformed
    3) Invoked the Db adapter to insert into "Header" table
    4) Added another Receive activity - To Read file (B) via File adapter
    5) Transformed
    6) Invoked the Db adapter to insert into "Line" table
    Issue - Step 4 gets fired as a SEPARATE instance (but no data in lines table) . At the end - I see the BPEL process which is waiting for File B. Even after I dropped File B - I dont see any records going into tables.
    Is there a better way to design this process? Do I need to separate BPEL process to insert into Header & Line table? If so - how can I make this sequential process?
    Appreciate detailed steps, if possible
    Thanks
    Babu

    If its really a SyncRead Step 4 willl not run as a seperate process.
    Step1: Initiates the process once the header file arrived
    Step4: Will be invoked like a normal partnerlink.
    Just make sure, you put the lines file before the header file in the directory.
    If it doesnot resolve the problem, send your project to me helloprasanna at rediffmail.com . I'll have a look.
    --Prasanna                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Do anybody know how to read file...

    Hello,
    I have a problem with reading config file. Do anybody know how to read config file from the same dir as class.
    Now the situation is like:
    filePath I hardcoded like:
    fileName = "C:\\apache-tomcat-5.5.17\\webapps\\ROOT\\WEB-INF\\classes\\config.sales";
    Is it possibility to read config file wich is used by java classes (in prj) from the same dir as classes are?
    Thanks in advance.

    If the file is in the class path you should be able to access it using the Class.getResourceAsStream method. It is the same concept as loading a properties file:
    http://www.javaworld.com/javaqa/2003-08/01-qa-0808-property_p.html

  • How to generate soap header using java code

    Hi,
    I need to generate the following soap header using java DOM.
    Can you send me some java code snippet to do so?
    <soapenv:Header>
    <api:RequesterCredentials soapenv:mustUnderstand="0" xmlns:api="urn:ThinkPod:api:ThinkPodAPI" xmlns:ebl="urn:ThinkPod:apis:eBLBaseComponents">
    <ebl:ThinkPodAuthToken>YourToken</ebl:ThinkPodAuthToken>
    <ebl:Credentials>
    <ebl:DevId>YourDevId</ebl:DevId>
    <ebl:AppId>YourAppId</ebl:AppId>
    <ebl:AuthCert>YourAuthCert</ebl:AuthCert>
    </ebl:Credentials>
    </api:RequesterCredentials>
    </soapenv:Header>

    You want to generate that on a mobile device or how is that related to CLDC and MIDP?

  • How to read file from server if I have a logical file path?

    Hi guys,
    I'm having a pretty "on the run" question,
    My program is currently reading a file from server using "open dataset" with file path like this (just example)
    /usr/interface/abc/bcd/testfile.dat
    Now I got a requirement to make it more consistent to read files, instead of reading that physical file name, I should read the files from a specific folder using logical path.
    So I go to T code "FILE" and created a logical path called ZABC_FILE_PATH, unix compatible, with physical path is (for example),
    /usr/interface/<sysid>/<client>/<filename>
    My question is, can I still use open dataset statement to read this? if yes, how do I do that? If no, there should be alternative way, please let me know what you think. Thanks,

    Thanks all, I figured it out.
    ONe thing is that typo double quote
    The other thing is the importing part, I need the full file path.
    CALL FUNCTION 'FILE_GET_NAME_USING_PATH'
      EXPORTING
        CLIENT                           = SY-MANDT
        logical_path                     = 'ZABC_MY_LOGICAL_FILE_PATH'
    *   OPERATING_SYSTEM                 = SY-OPSYS
    *   PARAMETER_1                      = ' '
    *   PARAMETER_2                      = ' '
    *   PARAMETER_3                      = ' '
    *   USE_BUFFER                       = ' '
        file_name                        =  v_1
    *   USE_PRESENTATION_SERVER          = ' '
    *   ELEMINATE_BLANKS                 = 'X'
      IMPORTING
        FILE_NAME_WITH_PATH              = v_what_I_need
    * EXCEPTIONS
    *   PATH_NOT_FOUND                   = 1
    *   MISSING_PARAMETER                = 2
    *   OPERATING_SYSTEM_NOT_FOUND       = 3
    *   FILE_SYSTEM_NOT_FOUND            = 4
    *   OTHERS                           = 5
    I really appreciate your contributions, thanks again!

  • How to read file from server

    Hi,
    When i try to read file from server,the following message is displayed .
    ORA-29532: Java call terminated by uncaught Java exception: java.security.AccessControlException: the Permission (java.io.FilePermission /tmp read) has not been granted to EWMTRACKTEST. The PL/SQL to grant this is dbms_java.grant_permission( 'EWMTRACKTEST', 'SYS:java.io.FilePermission', ' /tmp', 'read' )
    ORA-06512: at "EWMTRACKTEST.GET_DIRLIST_EWM", line 1
    ORA-06512: at line 1
    thanks and regards
    P Prakash

    it seems obvious, user EWMTRACKTEST doesn`t have access to directory /tmp and the file under that.
    try to give read permission and try again.
    you could use command line like 'chmod' to grant permissions.

Maybe you are looking for