Skip to content

Instantly share code, notes, and snippets.

@liorboord
Created September 8, 2012 14:40
Show Gist options
  • Save liorboord/3675524 to your computer and use it in GitHub Desktop.
Save liorboord/3675524 to your computer and use it in GitHub Desktop.
Jython - Convert File to Byte Array
from java.lang import Byte
from java.io import FileInputStream
from java.io import File
import jarray
def getByteArray(self,fileUrl):
file = File(fileUrl);
inputStream = FileInputStream(file)
length = file.length()
bytes = jarray.zeros(length, 'b')
#Read in the bytes
offset = 0
numRead = 0
while offset<length:
if numRead>= 0:
print numRead
numRead=inputStream.read(bytes, offset, length-offset)
offset = offset + numRead
return bytes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment