Getting a file?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TheMan1
    New Member
    • Mar 2008
    • 19

    #1

    Getting a file?

    Hi, I'm making a program that gets a file and sends it via a socket. The file to get will be specified by a String that the user enters. Problem is, I have no idea how you retrieve files.
    I've tried "File file = new File(input)" but that just creates a file (I think), doesn't actually retrieve an already existing one...
    Also, how would you then send said file via TCP? I cant do writeBytes(file ) on the socket's outputstream, since that method only takes Strings.

    Help? Thanks, and much appreciated.
  • pronerd
    Recognized Expert Contributor
    • Nov 2006
    • 392

    #2
    Originally posted by TheMan1
    I've tried "File file = new File(input)" but that just creates a file (I think), doesn't actually retrieve an already existing one...
    Google for some examples using the BufferedReader or BufferedInputSt ream, or FileReader classes. Any of them should be able to do what you want.



    Originally posted by TheMan1
    Also, how would you then send said file via TCP?
    That would depend on what service or server you wanted to connect to.





    Originally posted by TheMan1
    Also, how would you then send said file via TCP? I cant do writeBytes(file ) on the socket's outputstream, since that method only takes Strings.
    You can not pass a file object like that. You need to actually read the contents of the file and pass them to the method. Again google can provide a wealth of examples of this.

    Comment

    Working...