As I'm a brazilian colleague, i'll not give you the fish. I'll give you the rod. Right?
You're dealing with the I/O API of Java. If you really a representation of your file as an object to do something, the best approach is the one that you started to think.
If you really just need the content of the file you can do something like this:
Note that the method getResourceAsStream should be used carefully, once the classloader behind it is arbitrary and in an application server or web server can access a completely different folder.
This will return an InputStream that may be used to do whatever you want. You can create an byte array to use as a buffer and put the bytes that you've read there. The method read will return -1 if you reached the end of the stream. So you can iterate over the inputstream filling the buffer with the data read and then writing it to an OutputStream object like a FileOutputStream.
This is useful when you're dealing with some I/O operation through the network once the nature of networking that can become slower and can corrupt the data if you try to send an entire and large bunch of bytes over. But how I see that you're dealing with I/O operations that access the file system directly, you can use the inputstream returned from the snippet above and call available() method, it will return the amount of bytes available in the inputstream. You can use it to create your new byte array with the correct size of the input stream and then read it in just one call of the read method and then pass it to the FileOutputStream.
Note that once your new file doesn't exist yet, you'll really need an instance of File. Then you can pass to the constructor of your new instance of FileOutputStream.
I think with this you'll be able to do what you want, and if there is missing something you can ask again or research by yourself.
Feel free to ask again! Thanks!
Feel free to ask me anything!
www.BlackBeltFactory.com/ui#!/ref=jmotta, SCJP 6, OCWCD JEE5, OCE EJB JEE6
Joined: Feb 12, 2010
Thank you very much!
I'll think about this approach....
If I have any doubt you'll know....
And when I do it you'll know too...
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: How to read and after write a video (or any binary file)