将文件上传到HttpConnection - BLACKBERRY / JavaME

时间:2011-02-01 03:24:56

标签: java blackberry java-me

我喜欢将文件上传到http服务器。这是我到目前为止的代码。问题是文件根本没有上传。代码有什么问题?

更新:我已设法解决它。任何有相同问题的人,也许这段代码可能会有所帮助。

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();

1 个答案:

答案 0 :(得分:3)

您正在使用零长度字节数组调用InputStream.read(byte []),根据定义,该数组始终返回0(无字节读取),这就是您的while循环永不退出的原因。

嗯,那是你的第一个问题。此代码还有许多其他问题。