Get InputStream from file on disk?

I have used this for some time now, with:
InputStream realData = getClass().getClassLoader().getResourceAsStream(filename);But when I supply the full path 'realData' is null. It only works if the file is located in the resources folder under my project.
How do I create an InputStream to a file with the full path specified?
EDIT: Btw is only XML files that I am reading.
Edited by: fedevaps on Mar 23, 2009 10:24 PM

fedevaps wrote:
But when I supply the full path 'realData' is null. It only works if the file is located in the resources folder under my project.Of course, because you're explicitely requesting a resource from the classpath.
How do I create an InputStream to a file with the full path specified?Use a FileInputStream.
EDIT: Btw is only XML files that I am reading.That doesn't matter in this regard.

Similar Messages

  • Get data from file in server to client and vice versa

    after greeting
    i really didn't know how to use socket and serversocket to get data from file in the server and display it to client.
    also read file from client and save it to server.
    really i didn't know how to do it.
    really i want the reply as soon as possible

    You REALLY need to work through the Java networking tutorials:
    http://java.sun.com/docs/books/tutorial/networking/index.html

  • 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.

  • Getting data from file to array

    try
        System.out.println("Enter file name: ");
        fileName = Object.nextLine();
        BufferedReader inputStream =
                new BufferedReader(new FileReader(fileName));
        String employee = null;
        employee = inputStream.readLine();
        System.out.println("The first employee in " + fileName + " is");
        System.out.println(employee);
        inputStream.close();
    catch(FileNotFoundException e)
        System.out.println("File " + fileName + " not found ");
    catch(IOException e)
        System.out.println("Error reading from file " + fileName);
    }This is just a little example I made. You can look at my other thread to see the other code. I need to put the data in a file into the array. Does it need to be casted somehow?

    public void getData()
           try {
       System.out.println("Enter file name to read: ");
       File = Object.nextLine();
       BufferedReader Object =
                new BufferedReader(new FileReader(File));
        for(int i = 0; i < people.length && people[i] != null; i++)
    String temp = Object.readLine();
    people.setLastname(temp);
    temp = Object.readLine();
    people[i].setFirstname(temp);
    temp = Object.readLine();
    people[i].setID(temp);
    temp = Object.readLine();
    people[i].setPhone(temp);
    temp = Object.readLine();
    people[i].setYearlySalary(Double.parseDouble(temp));
    temp = Object.readLine();
    people[i].calcBonus(Double.parseDouble(temp));
    temp = Object.readLine();
    people[i].getMonthlyPay(temp));
    } Object.close(); }I know, I got careless with the naming. I'm trying a different route now. I think I can just do it in reverse. lol How would I get the method getMonthlyPay to have no errors. It's a public void() method with monthlyPay = (yearlySalary + bonus) / 12; in its definition.
    anyone?
    Edited by: Program_1 on Dec 9, 2007 5:42 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to get FILENAME from FILE PATH

    does anyone know how to get filename from a file path for example
    FILE PATH: C:\Project\uploadbean\web\uploads\Button.txt
    returns
    FILENAME: Button.txt

    @BalusC
    ust for a reference cause i'm new in JSP This has nothing to do with JSP, but with basic knowledge of an essential API. I have given you the link to the File API. Are you saying that you refused to read the API documentation, which clearly explains you how to use the File and shows which methods are all available to you undereach the straightforward getName() method, and expecting that the others may chew the answers for you? Loser.

  • 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

  • Getting data from old system disks

    My Mac Mini was blown up by a lightning strike. Blew the Ethernet port.
    I have a new machine and the drives from the old one. Borrowed a cradle from a friend. The drives mount.
    I can see and copy files from folders I made on the drives but the User areas appear to have no files.
    There were Images in iPhoto and documents in iBooks.
    I am guessing it is a permissions thing...
    How can I get my files of off the old system disk?
    Thanks
    SGC

    I doubt this is a permission issue, but if it is, you can resolve it as follows. Select the volume icon in the Finder and open the Info window. Click the padlock icon in the lower right corner of the window and enter your administrator password when prompted. Check the box at the bottom marked
    Ignore ownership on this volume
    Close the Info window.

  • Get filename from file sender adapter

    Hi Experts,
    I have a question regarding the file/ftp adapter (sender).
    I have a directory with xml and pdf files. for every xml file there is a pdf file with the same filename. for example:
    file1.xml
    file1.pdf
    file2.xml
    file2.pdf
    file3.xml
    file3.pdf
    Now I want to read the xml file with the file sender adapter. afterwards I want to read the related pdf file. for example: If I read the file file1.xml afterwards I want to read the pdf file file1.pdf with the file sender adapter. For this it is nessessary to get the filename from the xml file so that I can read afterwards the pdf file. How can I realise it?
    Thanks and best regards
    Christopher

    Hi srinivas,
    thanks for your quick answer.
    That the file adapter is not able to read pdf files is clear to me. In this case I only want to transport the pdf. that works fine. I tested it.
    the problem is the following:
    I have a xml file with the name "file1.xml". I read the xml file with the sender file/ftp adapter configured with filename "*.xml". Then I want to import the pdf file with the name "file1.pdf". Therefor I need the filename from the xml file.do you know what I mean? So XI has to know the filename of the xml to import the pdf with the same name ...
    regards

  • How to get InputStream from JTextArea.getText() string?

    hello,
    well the postname pretty much says it, i need to get an InputStream for the String of a JTextArea.
    thing is, i want to save the string in a textfile, but the new line isnt recognized when i write it to the file.
    FileWriter fw = new FileWriter ("text.txt");
    fw.write(editField.getText());  // editField is my JTextArea instanceso i thought of doing smth like this
    String lineSeparator = System.getProperty("line.separator");
    // somehow getting the InputStream for my editField and save it in "is"
    BufferedReader br = new BufferedReader(new InputStreamReader (is));
    String line;
    while ((line = br.readLine()) != null) {
    fw.write(line);
    fw.write(lineSeparator);
    }

    pSaiko wrote:
    hello,
    well the postname pretty much says it, i need to get an InputStream for the String of a JTextArea.
    thing is, i want to save the string in a textfile, but the new line isnt recognized when i write it to the file.
    FileWriter fw = new FileWriter ("text.txt");
    fw.write(editField.getText());  // editField is my JTextArea instanceso i thought of doing smth like this
    String lineSeparator = System.getProperty("line.separator");
    // somehow getting the InputStream for my editField and save it in "is"
    BufferedReader br = new BufferedReader(new InputStreamReader (is));
    String line;
    while ((line = br.readLine()) != null) {
    fw.write(line);
    fw.write(lineSeparator);
    This is very simple, it isn't buffered, but it should work for you.
    Sting s = editfield.getText();
    for(int i=0; i<s.length();i++) fw.write((int)s.charAt(i));
    fw.flush();
    fw.close();

  • Getting path from file

    Good Morning,
    Is there a way to get a file path from a file without having to select it through client_get_file_name?
    for example i have a file 'test_01.txt' in C:/
    I cannot hard code the path as each day the txt name will change eg. 'test_02'.
    Is there another way to select the full path name in C:/ where file like 'test%'?
    Thank you in advance,
    D

    Sorry francois ill be a more clear
    On a variable i want to keep changing the path provided.
    For example one day will be var:='C:/Test_01'
    next day will be var:='C:/Test_03'
    as the last number is generated randomly im trying to figure a way to get the correct path in C:/ where the name corresponds to 'test' so i can pass it to my variable
    Edited by: 794018 on 18-Oct-2012 00:50

  • Get Media From Files & Folders is Broken

    In premiere elements 9, whenever I go to organize, get media, files and folders, it takes 30 seconds to open the explorer window, and when it does it comes up blank. It still has the tabs on the side like recent places and desktop, but no matter what I click or do, it wont show any files or folders! What do I do?

    lillianstreet
    More questions to add to SG's questions....
    Are you running Premiere Elements 9 as the 9.0.1 Update?
    Do you have the latest version of QuickTime installed?
    Are you running the program as Run As Administrator or from a User Account with Administrative Privileges?
    Now that we have gotten the usual questions out of the way.....
    1. Is your video card driver up to date according to the web site of the manufacturer of the video card?
    2. If the video card driver is up to date, then delete the BadDrivers.txt file found in the Windows 7 or 8 64 bit path:
    Local Disc C
    Program Data
    Adobe
    Premiere Elements
    9
    and in the 9 Folder is the BadDrivers.txt file that you delete.
    Make sure that you are working with Folder Option Show Hidden Files, Folders, and Drives active so that you can see the complete path.
    3. We could try deleting the Adobe Premiere Elements Pref file or the whole folder that it exists
    Local Disc C
    Users
    Owner
    AppData
    Roaming
    Adobe
    Premiere Elements
    9
    and in the 9 Folder is the Adobe Premiere Elemens Prefs file that you delete. Same comment as above regarding the Folder Option "Show Hidden Files, Folders, and Drives".
    4. After that comes the uninstall, run through of ccleaner, reinstall.
    We will be watching your progress and your replies to SG.
    Thanks.
    ATR
    With all those questions, I nearly forgot to ask "Is this a it never worked before issue" or "Did this work before but not now" type issue?

  • Cannot get InputStream from XMLType

    Hello,
    I am using java to execute a query that return an xml document and I experience a problem while trying to get the content as an InputStream.
    The received XMLType object is correct, I can get the xml as a String using the XMLType.getStringVal() method, but when I try to get the InputStream I an getting the following error:
    java.lang.UnsatisfiedLinkError: oracle/xdb/XMLType.getInputStreamNative(JJJ)J
         at oracle.xdb.XMLType.getInputStream(XMLType.java:1217)
    Any idea about what can cause this error?
    I am using Oracle XMLDB 10.2.
    I am accessing it using OCI driver.
    Thank you.

    I just saw your posting - I'm trying to access XML DB from JUnit tests, on a windows machine, within Weblogic Workshop. Do you have any advice for getting this working?
    The error I'm getting is:
    java.lang.UnsatisfiedLinkError: no ocijdbc11 in java.library.path
         at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1682)
         at java.lang.Runtime.loadLibrary0(Runtime.java:823)
         at java.lang.System.loadLibrary(System.java:1030)
         at oracle.jdbc.driver.T2CConnection$1.run(T2CConnection.java:3171)
         at oracle.jdbc.driver.T2CConnection.loadNativeLibrary(T2CConnection.java:3167)
         at oracle.jdbc.driver.T2CConnection.logon(T2CConnection.java:233)
         at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:490)
         at oracle.jdbc.driver.T2CConnection.<init>(T2CConnection.java:133)
         at oracle.jdbc.driver.T2CDriverExtension.getConnection(T2CDriverExtension.java:53)
         at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:474)
         at java.sql.DriverManager.getConnection(DriverManager.java:582)
         at java.sql.DriverManager.getConnection(DriverManager.java:207)
    ocijdbc11.dll IS in the Oracle product install (unlike the last time I saw this with orageneric11 being looked for, but orageneric10 having been installed), the BIN directory IS in my path, and I'm pretty much at a loss for how to deal with this. Any advice will be appreciated...
    Thanks,
    -=Alan

  • Get Information From File Name

    Hi,
    I have a somewhat general question, is it possible to extract certain "elements" from a file name?
    For example: x0 xxx abc 123 xx xxxx.avi (or any type txt, jpg, and etc...).
    Assuming that the "abc" is constant throughout the files but the digits are changing (not sequential), can I extract just the "abc 123" (or whatever number it is)?
    I know how to strip/build path, but here I don't know what to search since the distance from the beginning is changing and the digits are changing.
    Thank you,
    Solved!
    Go to Solution.

    There are several string function that allow you to search for a string, and  break the string into several parts.
    Another option is using Regular Expression, yours sound like "abc/s[0-9]{3}", that should return the "abc 123" part.
    Ton
    Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
    Nederlandse LabVIEW user groep www.lvug.nl
    My LabVIEW Ideas
    LabVIEW, programming like it should be!

  • Php - get name from 'file field' and pass to database?

    Is it possible to extract the 'image' name from the 'file' field and insert it into a database using php?
    <input type="file" name="ImageName" id="ImageName">
    I can't have:
    $ImageName = trim($_FILE['ImageName']);
    So hows this handled?
    Cheers
    Os

    Murray *ACP* wrote:
    Should be pretty strightforward, Os.  You know where to ask the questions!
    Yeah.. but I keep coming up against brick walls
    I'm trying to manipulate David Powers PHP Solutions chapter 6 - Uploading Files.
    He's got some sort of complicated function going on which makes sure no two images which are uploaded to a folder have the same name. i.e., london.jpg becomes london_1.jpg. (the php even inserts underscores if there are gaps in the image name)
    If I just use $ImageName = $_FILES["ImageName"]["name"]; potentially I could end up with dozens of images with the same name in the database, which is NOT desirable.
    Of course I could simplyfy everything and use two forms - 1 for uploading the images to the upload folder and then one for inserting the images details into the database BUT that has the drawback of the client needing to type in the name of the image identically to match the name which has been generated in the upload folder and that aint gonna happen in a million years

  • Getting Bitmaps from files uses excessive memory

    When I load a jpg picture as a bitmap I lose a lot of memory that I am unable to recover.
    I use the GetBitmapfromfile, the GetBitmapInfo, then GetBitmapData, then DiscardBitmap.
    after this I have about 120 M of memory (for a 5 M pixel image) missing that I cannot recover.  The size of this lost memory is proportional to the number of pixels in the image.
    Solved!
    Go to Solution.

    Hi Kelly
    Thanks for your response.  I am using CVI 8.1.0.  I detect the memory through using windows task manager. 
    My real problem is that my final application is using too much memory and going into virtual memory too much, when I have been tracing my memory usage I have a lot of memory unaccounted for and I cannot get it back.  This happens when I load the bitmap, and cannot be recovered untill my program is stopped.
    I have attached some code with pictures to try (use the 2 DSCxxx for comparision to my run).  I have also enclosed screen shots so you can see how the memory is used on my PC.  Sorry for the large file size, I thought it best to send the same sample photos I have been using.
    Attachments:
    CVI Test.zip ‏4944 KB

Maybe you are looking for

  • Reg:Steps in IDOC Scenario

    Hi,     I am very new to IDOC concept so can anyone tell me what is the use and why do we want to create, 1)RFC Destination 2)Port 3)Logical sysytem name 4)Partner Profile ,in IDOC Scenario and also let me know the steps that I have to implement  whi

  • Check if app window is visible

    Hi, I would like to check if the window of an app is visible. If it is visible it should get hidden. If it is not visible it should get activated. Can someone here help me on this? I just don't know how to write the if-statement properly. thanks! P.S

  • CAF (Composite Application Framework) and ESA

    Hi, As far as I understand, XApps is presented as a piece of Netweaver (the column on the left side of the NetWeaver stack), an XApps is also a kind of business process based on several applications (or services ?). XApps runtime and composition plat

  • Export FCP 6 preferences to FCP 7

    I just move to snow leopard and FCP 7,I would like to export FCP 6 preferences (settings,favorites transitions) to FCP 7,I tried with Preference manager,but it doesnt work here...what about u...

  • Can I do this in iWeb 2?

    Here is a link to site I created using iweb 1 and a bit of HTML tweaking: http://www.thirdspace.co.uk Would someone be able to walk (and I mean walk!) me through how to achieve this in iweb 2? I am referring specifically to the edited links, and the