I want to send file with OutputStream,
so I use byte[] = new byte[size of file ]
but I don't know what the max size is that i can use.
This is my code.
File file = new File(sourceFilePath);
if (file.isFile()) {
try {
DataInputStream diStream = new DataInputStream(new FileInputStream(file));
long len = (int) file.length();
if(len>Integer.MAX_VALUE){
file_info.setstatu("Error");
}
else{
byte[] fileBytes = new byte[(int) len];
int read = 0;
int numRead = 0;
while (read < fileBytes.length && (numRead = diStream.read(fileBytes, read,
fileBytes.length - read)) >= 0) {
read = read + numRead;
}
fileEvent =new File_object();
fileEvent.setFileSize(len);
fileEvent.setFileData(fileBytes);
fileEvent.setStatus("Success");
fileEvent.setSender_name(file_info.getSender_name());
}
} catch (Exception e) {
e.printStackTrace();
fileEvent.setStatus("Error");
file_info.setstatu("Error");
}
} else {
System.out.println("path specified is not pointing to a file");
fileEvent.setStatus("Error");
file_info.setstatu("Error");
}
Thanks in advance.