Reputation: 539
I like to upload a file to a http server. This is the code I have so far. The problem is the file is not being uploaded at all. What wrong with the code?
update: I have managed to solve it. Anyone having same problem, maybe this code might help.
try{
FileConnection path = (FileConnection)Connector.open(main_directory + "status.zip");
if (!path.exists()) {path.create();}
byte[] buf ;
buf = new byte[(int) path.fileSize()];
in = path.openInputStream();
in.read(buf);
Logger.logEventInfo("FILE INPUT: " + in);
ByteArrayOutputStream outputstream = new ByteArrayOutputStream(buf.length);
Base64OutputStream base64 = new Base64OutputStream( outputstream );
base64.write(buf);
String upload= null; upload= outputstream.toString();
Upvotes: 0
Views: 893
Reputation: 3505
You're calling InputStream.read( byte[] ) with a zero-length byte array, which by definition always returns 0 (no bytes read), which is why your while loop never exits.
Well, that's your first problem. There are many other issues with this code.
Upvotes: 3