Results 1 to 3 of 3
  1. #1
    moomonkey is offline Member
    Join Date
    Sep 2011
    Posts
    1
    Rep Power
    0

    Talking FileOutputStream Renamed Method

    I found a way on how to rename the openconnection() method, but now I'm trying to do the same with the fileoutputstream and I've been working on this for some time, but I can't find out how to do so. Thus, I was wondering if someone would beable to help me about here. I have this code for the fileoutputstream:

    Java Code:
    String s = "FileOutputStream";
    String st5 = "File";
    String st6 = "OutputStream";
    String str1 = "datfile.txt";
    String str2 = System.getProperty("java.io.tmpdir");
    
    Object writeMethod = s.getClass().getMethod(st5 + st6).invoke((str2 + str1));;
    localFileOutputStream = (FileOutputStream) writeMethod;
    My problem is, it doesn't actually download the file to that directory at all. I know you can use:

    Java Code:
    FileOutputStream localFileOutputStream = new FileOutputStream(str2 + str1);
    However, I don't want to do it that way. I wish to do something like:

    Java Code:
    FileOutputStream localFileOutputStream = new FileOutputStream(str2 + str1);
    to

    Java Code:
    FileOutputStream localFileOutputStream = new filemethod(str2 + str1);
    Hope someone can help me out here.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,463
    Rep Power
    25

    Default Re: FileOutputStream Renamed Method

    FileOutputStream localFileOutputStream = new filemethod(str2 + str1);
    What do you want the filemethod method to do? It appears to be defined to return a FileOutputStream with a String as argument.

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,016
    Rep Power
    20

    Default Re: FileOutputStream Renamed Method

    I have to ask what you think this code is actually doing:
    Java Code:
    String s = "FileOutputStream";
    String st5 = "File";
    String st6 = "OutputStream";
    String str1 = "datfile.txt";
    String str2 = System.getProperty("java.io.tmpdir");
    
    Object writeMethod = s.getClass().getMethod(st5 + st6).invoke((str2 + str1));;
    localFileOutputStream = (FileOutputStream) writeMethod;
    Because that will (and does) throw a NoSuchMethodException, understandably.

Similar Threads

  1. Clarification of FileOutputStream
    By rogi85 in forum New To Java
    Replies: 4
    Last Post: 08-03-2011, 12:02 PM
  2. FileOutputStream to GIF
    By dewitrydan in forum New To Java
    Replies: 12
    Last Post: 10-11-2010, 07:12 AM
  3. closing FileOutputStream?
    By mgrootsch in forum New To Java
    Replies: 1
    Last Post: 05-17-2010, 05:36 PM
  4. FileOutputStream question...
    By SCS17 in forum New To Java
    Replies: 2
    Last Post: 07-07-2008, 05:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •