try
{
FileOutputStream fos = new FileOutputStream("test.txt");
ByteArrayInputStream in = new ByteArrayInputStream(new byte[] {'a', 'b',
'c', 'd'});
// Create a buffer for reading the files
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0)
{
fos.write(buf, 0, len);
}
}
catch (FileNotFoundException fnf)
{
System.out.println(fnf.getMessage());
}
catch (IOException ioe)
{
System.out.println(ioe.getMessage());
}
>
>x = FileOutputStream(File file);
>x.write(byte[] b);
>
>On Wed, 2006-07-05 at 12:24 +0200, Roger Baatjes wrote:
>> Nope. Or may, I'm not using it correctly.
>>
>> Is there not any Util in java that can load a File from a byte[]?
>>
>> -----Original Message-----
>> From: [email protected] [mailto:[EMAIL PROTECTED]
>> On Behalf Of Albert Strasheim
>> Sent: 05 July 2006 12:02
>> To: [email protected]
>> Subject: [CTJUG Forum] Re: Loading a java.io.File from a Byte[]
>>
>>
>> Hey Roger
>>
>> Roger Baatjes wrote:
>> > Here is my code to read bytes from a File. I now need to get a
>> > java.io.File from a byte Array[]. The byte array represents the file I
>>
>> > need to send.
>> >
>> > How do I do that please?
>> > --------------------------------------------
>> >
>> > InputStream is = new FileInputStream(file); byte[] bytes = new
>> > byte[(int)length];
>> >
>> > int offset = 0;
>> > int numRead = 0;
>> > while (offset < bytes.length
>> > && (numRead=is.read(bytes, offset,
>> > bytes.length-offset)) >=
>> > 0) {
>> > offset += numRead;
>> > }
>>
>> Does ByteArrayInputStream and ByteArrayOutputStream solve your problem?
>>
>> Regards,
>>
>> Albert
>>
>>
>>
>>
>> >
>
>
>>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CTJUG Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/CTJUG-Forum
For the ctjug home page see http://www.ctjug.org.za
-~----------~----~----~----~------~----~------~--~---