文件名称:android 上传文件
文件大小:58KB
文件格式:RAR
更新时间:2014-02-16 03:30:33
android 上传文件
android 上传文件 progressBar.setMax((int)file.length()); String sourceid = fileService.find(file); Socket socket = new Socket("192.168.1.157", 7878); OutputStream outStream = socket.getOutputStream(); String head = "Content-Length="+ file.length() + ";filename="+ file.getName() + ";sourceid="+ (sourceid==null? "" : sourceid)+"\r\n"; outStream.write(head.getBytes()); PushbackInputStream inStream = new PushbackInputStream(socket.getInputStream()); String response = StreamTool.readLine(inStream); System.out.println(response); String[] items = response.split(";"); String id = items[0].substring(items[0].indexOf("=")+1);//服务返回绑定该文件的资源id String position = items[1].substring(items[1].indexOf("=")+1); if(sourceid==null) fileService.save(file, id); RandomAccessFile fileOutStream = new RandomAccessFile(file, "r"); fileOutStream.seek(Integer.valueOf(position)); byte[] buffer = new byte[1024]; int len = -1; int length = Integer.valueOf(position); while( (len = fileOutStream.read(buffer)) != -1){ outStream.write(buffer, 0, len); length += len; Message msg = new Message(); msg.getData().putInt("size", length); handler.sendMessage(msg); } fileOutStream.close(); outStream.close(); inStream.close(); socket.close(); if(length==file.length()) fileService.delete(file);
【文件预览】:
FileUpload
----.project(846B)
----default.properties(364B)
----bin()
--------cn()
--------FileUpload.apk(18KB)
--------resources.ap_(11KB)
--------classes.dex(11KB)
----AndroidManifest.xml(1KB)
----src()
--------cn()
----res()
--------values()
--------layout()
--------drawable-ldpi()
--------drawable-hdpi()
--------drawable-mdpi()
----.classpath(280B)
----gen()
--------cn()
----assets()