Don't write your own data transfer code, unless you have a very specific reason to do so. There are many data transfer java libraries: IOUtils, some parts of Apache Mina, etc. You should not reinvent the wheel, unless you want to do it for a school project or you see a weakness in the existing solutions which you want to improve on.
Also, speaking of bad practices, you shouldn't be using java's Date, but rather a more sane Date functionality, like Joda's DateTime and you shouldn't be opening/closing your own streams but either use a library that does it for you or use Java 7's Closable and try-with-resources statement.
EDIT: Another bad practice you do in your example is that you use java.util.Date to obtain the current time. This is wrong on two levels: code readability and thread safety.
For the code readability part: what you are trying to do is 'give me the current time'
, which you can clearly do by System.getCurrentTimeMillis()
. What you are actually doing is:
'allocate a semi-deprecated object, don't specify timezone or locale (which might change from the first call to the second call), don't be thread-safe, and give me its current time so I can use it as my current time'
. Creating two extra objects when you can easily avoid it is not a big deal, but since a method for giving you the current time exists, and it is more efficient, you should use it, otherwise you are developing bad practices.
For the thread safety part, you can read this: How to make Java.util.Date thread-safe
Just code using java.util.Date is inherently prone to errors and you shouldn't be using it. It might not seem like a big deal in this example, but details are important if you are developing yourself as a software engineer. In addition, you shouldn't be writing your own methods for data transfer unless you know what is wrong with the existing ones and you want to improve on that or you are doing it for the purpose of a homework or study.