服务器端代码:
其他代码由IDE生成,就不记录了。
- package ws;
- import java.io.*;
- public class Upload {
- public void upload(String name, byte[] content) {
- try {
- File f = new File("d:/" + name);
- FileOutputStream fo = new FileOutputStream(f);
- fo.write(content);
- fo.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
客户端代码:
- package ws;
- import java.io.*;
- public class Test {
- public static void main(String[] args) throws IOException {
- UploadDelegate d = new UploadService().getUploadPort();
- File f = new File("j2me中文教程.pdf");
- FileInputStream fi = new FileInputStream(f);
- byte[] b = new byte[fi.available()];
- fi.read(b);
- d.upload(f.getName(), b);
- fi.close();
- System.out.println("上传完毕!");
- }
- }