How to get InputStream from a file with absolute path?

Hi, guys:
If I have file with a absolute path that may be inside/outside
my Eclipse plugin, I want to get an InputStream from it. It just keeps giving me null for "is":
String absFilePath = "/D:/my_dir/.../sample_file.txt";
InputStream is = getClass().getResourceAsStream(absFilePath);
regards,

Don't use resource as stream if you have an absolute path, use FileInputStream.

Similar Messages

  • How to get InputStream of uploaded file from request?

    The situation:
    Client is uploading xml file to server.
    <form METHOD=POST ENCTYPE = "multipart/form-data" action="SendFile" accept="text/xml">
              <input type="file" name="SentFile" />
              <input type="submit" value="go"/>
    </form>Then I need to parse data from file.
    I want to use method javax.xml.parsers.DocumentBuilder.parse(InputStream is)
    But, how to get InputStream of uploaded file from request?

    You cannot get the InputStream of the uploaded file directly. The InputStream you can obtain from request.getInputStream() contains a lot of other data as well as the uploaded file. You will have to parse the data in the InputStream to find the data that belongs to the file.
    A short cut is to use the HTTP Multipart File Upload available from www.jenkov.com. It simplifies file upload and makes it easy to obtain an InputStream for only the uploaded file. It also handles upload of multiple files. It is free, open source, Apache license, so if it doesn't fit your needs, you can always read the code and see how it works. Then write your own upload servlet.

  • How to extract data from XML file with JavaScript

    HI All
    I am new to this group.
    Can anybody help me regarding XML.
    I want to know How to extract data from XML file with JavaScript.
    And also how to use API for XML
    regards
    Nagaraju

    This is a Java forum.
    JavaScript is something entirely different than Java, even though the names are similar.
    Try another website with forums about JavaScript.
    For example here: http://www.webdeveloper.com/forum/forumdisplay.php?s=&forumid=3

  • How to get string from jtextpane along with its attributes

    sir,
    How to get string from jtextpane along with its attributes
    i,e font,size,style,color etc.
    please help me out.
    my mail id is [email protected]

    JTextPane extends JTextComponent
    JTextComponent.getDocument()
    a Document is a set of Element, see Document.getRootElements(). Each Element has attributes, stored within an AttributSet object see Element.getAttributes()
    a Document can also be rendered as a String, see Document.getText( offest, length ), use it with 0 and Document.getLength() as parameters.

  • How to get Text from (.txt) file to display in the JTextArea ?

    How to get Text from (.txt) file to display in the JTextArea ?
    is there any code please tell me i am begginer and trying to get data from a text file to display in the JTextArea /... please help...

    public static void readText() {
      try {
        File testFile = new File(WorkingDirectory + "ctrlFile.txt");
        if (testFile.exists()){
          BufferedReader br = new BufferedReader(new FileReader("ctrlFile.txt"));
          String s = br.readLine();
          while (s != null)  {
            System.out.println(s);
            s = br.readLine();
          br.close();
      catch (IOException ex){ex.printStackTrace();}
    }rykk

  • How to get the current executing file/itself absolute directory?

    hellooo,
              gentlemen/lady, how to get the current executing file/itself absolute directory?
              thanks
              

              Hello,
              you can get the real path information of the JSP through the servlet context:
              http://java.sun.com/products/servlet/2.2/javadoc/index.html
              javax.servlet
              Interface ServletContext
              Method getRealPath
              Christian Plenagl
              Developer Relations Engineer
              BEA Support
              [email protected] (alex mok) wrote:
              >hellooo,
              >
              >gentlemen/lady, how to get the current executing file/itself absolute
              >directory?
              >
              >thanks
              

  • How to get data from a file?

    Hello everyone, i'm new to this forum and to java too. Ok, so here is what i want to do:
    I want to get data from a file containing words and numbers and store them into variables that i will use them after to insert into a database table. For example i have a file called employees.txt in this form:
    eid ename zipcode Hire_date
    1000 "Jones" 67226 "12-DEC-95"
    In C++ i declare variables for each data and store them, for example in this case:
    ifstream in("somefile");
    string name, hdate;
    int eid, zip;
    in >> eid >> ename >> zip >> hdate;
    So i want to do the same thing in JAVA but i can't make it work. So, i would appreciate if someone could give me a simple example how to do it. Thank you.

    [http://java.sun.com/docs/books/tutorial/essential/io/index.html]

  • How to create PDF from text file with specific layout?

    I wanted to create the pdf from text file in specific layout - Landscape orientation and JIS B3 Page size while at Adobe Acrobat Pro.
    In past, I could do a right click on a text file (desktop area) and select print to print out the document into .pdf BUT only if I set the Adobe PDF to Landscape and JIS B3 Page size BEFORE.  And I could only do 15 text documents at once.
    I wanted to see if I could do the create the pdf from text file with specific layout in Adobe Acrobat without having to go to Control Panel to preset the Adobe PDF to specific layout at every time.   I would have to set Adobe PDF back to normal layout after I'm done with these pdf print outs.  I do lots of pdfs in normal layout.  Sometimes I would forget to do that.
    So, How do I do that?

    No such luck.  It would output the contents in letter size even in JIS B3 Page layout at MS word. 
    Is there a script or action where I could set the orientation and page size before creating PDF on these text files?

  • How to get InputStream in jar file

    Could anyone give me a tip how I can play this sound file inside the application jar file?
    I have this package: *{color:#0000ff}com.sikgraf.ui{color}*
    with *{color:#ff6600}ArquivoMagneticoUI.class{color}* and {color:#ff6600}*applause.au*{color}
    I am tyring to get the InputStream but It's being painful and so far no success
    Here are the 3 ways I tried:
    InputStream is = ArquivoMagneticoUI.class.getResourceAsStream("applause.au");
    is = getClass().getResourceAsStream("applause.au");
    is = this.getClass().getClassLoader().getResourceAsStream("applause.au");All them return:
    java.lang.NullPointerException
            at java.io.FilterInputStream.mark(FilterInputStream.java:175)
            at com.sun.media.sound.WaveFileReader.getFMT(WaveFileReader.java:241)
            at com.sun.media.sound.WaveFileReader.getAudioInputStream(WaveFileReader.java:160)
            at javax.sound.sampled.AudioSystem.getAudioInputStream(AudioSystem.java:1094)What I am doing wrong?

    Thanks for your reply, I just figured out using URL:
        public static void playSound(int index) {
            String files[] = {"applause.au", "cash_register.au", "ding.au", "donkey_1.au", "duck_1.au", "siren_2.au"};
            String sound = "som/" + files[index];
            try {
                URL url = ArquivoMagneticoUI.class.getResource(sound);
                AudioInputStream ain = AudioSystem.getAudioInputStream(url);
                AudioFormat format = ain.getFormat();
                if (format.getEncoding() != AudioFormat.Encoding.PCM_SIGNED) {
                    format = new AudioFormat(
                            AudioFormat.Encoding.PCM_SIGNED,
                            format.getSampleRate(),
                            format.getSampleSizeInBits() * 2,
                            format.getChannels(),
                            format.getFrameSize() * 2,
                            format.getFrameRate(),
                            true);        // big endian
                    ain = AudioSystem.getAudioInputStream(format, ain);
                DataLine.Info info = new DataLine.Info(Clip.class, ain.getFormat(), ((int) ain.getFrameLength() * format.getFrameSize()));
                Clip clip;
                clip = (Clip) AudioSystem.getLine(info);
                clip.open(ain);
                clip.start();
            } catch (LineUnavailableException ex) {
                //Logger.getLogger(ArquivoMagneticoUI.class.getName()).log(Level.SEVERE, null, ex);
            } catch (UnsupportedAudioFileException ex) {
                //Logger.getLogger(ArquivoMagneticoUI.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                //Logger.getLogger(ArquivoMagneticoUI.class.getName()).log(Level.SEVERE, null, ex);
        }

  • How to get resources from jar-files

    Hi
    in my app I load an image via the Toolkit.getImage() method.
    Works fine if the app and the image are in folders on disk.
    It fails to load the image, if the app (and the image) is packed in a jar file.
    How can I get the image from there?
    I try to get the image as follows:
    String s = getClass().getResource("MyApp.class").getFile();
    AppPath = s.substring(0,s.lastIndexOf("/"));
    String PathToImages = "/images";
    MyImage = (Image)Toolkit.getDefaultToolkit().getImage(AppPath+PathToImages+"/logo32.gif");The App starts and works, it just fails to load the images.
    Any solutions??
    thanx in advance
    Herby

    This is actually pretty easy. First a little background.
    A Jar file is just a Zip file, with a few constructs for Java.
    The getResource() method is used to create a mapping to data within the Jar file, but is actually not necessary after you know how the mapping works.
    Just to give you an example of getResource:
    // returned is a url to the resource you want from your Jar file.
    URL myURL = MyClass.class.getResource("images/myimgage.gif");
    // then you can use this URL to load the resource
    Image img = getImage(myURL);If you were you look at the value of myURL you would see something similar to the followiing.
    jar:http://www.mywebsite.com/mydir/myjarfile.jar!/images/myimage.gifJust to break it down for you.
    The line always starts with the word jar:
    Followed by the path to your jar file.
    A sepearator !/
    Then the file you are loading from the Jar file.
    jar:     path_to_jar_file     !/     path_to_resource_in_jar_fileSo if you'd like, you could just create a URL object, and define the path to the object using the above method rather than using getResource.
    Anyway, back to your code. What I would do is print out what you get for:AppPath+PathToImages+"/logo32.gif"I'm thinking you might be getting 2 "/" in your path because I think:AppPath = s.substring(0,s.lastIndexOf("/"));will leave the "/" at the end and the next line you add the "/" in front of the image directory name. So you my have the following for your image path.mypath//images

  • How to import data from CSV file with columns separated by semicolon?

    I migrate database from MS SQL 2008 to ORACLE 11g
    I export data to CSV file from MS SQL
    then I try to import it to Oracle
    several tables goes fine using Import data option in the SQL Developer
    Standard CSV files with data separated by comma were imported.
    chars, date (with format string), and integer data are imported via import wizard without problems
    the problems were when I try to import table with noninteger numbers with modal part separated by comma not by dot
    comma is the standard separator for columns in CSV file
    so I must change the standard separator to semicolon
    then the import wizard have problem to correct recognize the columns data because it use only standard CSV comma separator :-/
    In SQL Developer 1.5.3 Tools -> Preferences -> Migration -> Data Move Options
    I change "End of Column Delimiter" to ; but it doens't work
    Is this possible to change the standard column separator for import data wizzard in SQL Developer 1.5.3?
    Or maybe someone know how to import data in SQL Developer 1.5.3 from CSV when CSV colunn separator is set to semicolon?

    A new preference has been added to customize the import delimiter in main code line. This should be available as part of future release.

  • How to get InputStream from String ?

    Hi !
    I want to get InputStream object from String.
    String str = "balabalabala";
    InputStream stream = getInputStream(str);
    How to realize getInputStream(str) function ?
    Thanks!

    The preferred method nowadays is to use Readers and Writers for String data - hence StringReader(String). If you're going to operate on the InputStream directly, then I'd modify your code to use the Reader calls and go that route.
    If, however, you need to pass the InputStream to some other piece of API that requires an InputStream instead of a Reader, then the ByteArrayInputStream is probably your best bet. StringBufferInputStream is deprecated because it doesn't work reliably in the face of many character encodings.
    Speaking of encodings - never call Strng.getBytes() - always use the getBytes(character-encoding) version, so you KNOW what encoding you're getting!
    Grant

  • How to get data from XML file having korea Text

    I have a one XML File with Korean Text, How to read this File.
    i tried with this code
    BufferedReader in = new BufferedReader(
    new InputStreamReader(new FileInputStream("C:/test1.xml"), "EUC-KR"));
    String str = in.readLine();
    but it is giving exceptions.
    please suggest me, how to retrive EUC-KR text from the XML file

    Standard Java does not support this Charset. You have to find a charset provider that implements "EUC-KR". But you should also consider using Unicode, which is implemented in standard Java.
    http://www.unicode.org/charts/

  • Help Me... How to get Data from CSV File...?

    Hi Everyone..!
    This is yajiv and am working in CS3 Photoshop platform. I know about Java Script. Is it possible to get the data from CSV files. Actually our client use to send us the CSV files which contains a lot of swatch name and reference files in one particular image name.
    Actually how we work on that CSV file is, first we copy file name to search that CSV file. then get the result to paste into layer name. This process continue till the end of swatch.
    Thank in Advance
    -yajiv

    > Is it possible to get the data from CSV files.
    Have you tried searching this forum?

  • How to get info from imported file in an outbound campaign IVR-based. UCCX 8.5.

    Hello.
    Somebody knows if it is possible to get the information inside my ivr script from the file imported when I create an outbound campaign IVR-based?
    I want to store in variable data like first name, last name, account number... And use them in the flow of my IVR script.
    I´m using UCCX 8.5.
    Regards

    did you get this to work ?

Maybe you are looking for

  • Help with HP Deskjet Ink Advantage 2020hc

    why after printing a document, my printer always paper jam, all paper is out whit no printing, just out from tray, until out of paper..after that my printer stil blinking whit error "paperjam" This question was solved. View Solution.

  • Flash-Web Photo Gallery

    I am trying to create a flash web photo galler using the Automate>Web Photo Gallery in CS2. I want to mix the features of the 2 existing options. In Flash Gallery 1, the thumbnails are listed as small icons in multiple lines and are magnified when th

  • FCC Content convertsion problem

    Hi Experts, I have the following strucrure. Cust no Sales org Dist Channel division Indicator1 partner function1 partner no1 Indicator2 partner function2 partner no2 Indicator3 partner function3 partner no3 Here The customer no will appear some times

  • How to assign function module with process code in IDOC ?

    how to assign function module with process code in IDOC ? and what code i have to write in that function module for custom IDOC ? helpful answer will be rewarded?

  • I can't open javascript:void(0) after I update to firefox 3.6.21

    at first the plugin java development toolkit was disabled by firefox,I checked java website and upgrade to newest version, the plugin was enabled. however, I still can't open any links which shows javascript:void(0) . please help me solve this proble