2010-06-27 40 views
2

我如何修改下面的Java代码,以便它可以在J2RE(Java ME),因为没有java.io.files类的Java ME :(上传文件通过FTP使用Java ME

public static void main(String[] args) { 
    // TODO code application logic here 

    try 
    { 
     FTPClient client = new FTPClient(); 
     client.connect("serveraddy"); 
     client.login("user", "pass"); 
     client.upload(new java.io.File("C://text.txt")); 
    } catch(Exception e) { 
     e.printStackTrace(); 
    } 

} 
+0

下次您在此处发帖时,请记住格式化您的文本。另外,它不是JavaME,它是Java ME。 **; - )** – 2010-06-28 00:55:56

回答

2

如果你想要做的是打开和读取文件然后看这两个环节

http://developers.sun.com/mobility/apis/articles/fileconnection/index.html
http://developers.sun.com/mobility/midp/articles/genericframework/index.html

下面是打印的小故事样本文件的nts ...

public void showFile(String fileName) { 
    try { 
     FileConnection fc = (FileConnection) 
     Connector.open("file:///CFCard/" + fileName); 
     if(!fc.exists()) { 
     throw new IOException("File does not exist"); 
     } 
     InputStream is = fc.openInputStream(); 
     byte b[] = new byte[1024]; 
     int length = is.read(b, 0, 1024); 
     System.out.println 
     ("Content of "+fileName + ": "+ new String(b, 0, length)); 
    } catch (Exception e) { 
    } 
} 
+0

我实际上正在开发一个客户端应用程序,我需要整合此功能,您提供的链接是一个ftp客户端,不是开发aps的api或类,也是其商业版:< – brux 2010-06-27 23:01:03

+0

@brux现在我很困惑你需要什么。您是否在寻找J2ME的FTP客户端API?如果是这样,或者如果不是,请澄清你的问题,这是非常模糊的,你在问什么。 – 2010-06-27 23:10:26

+0

感谢您的回复Romain。 基本上我想知道如何使用java.io.files部分,以便它使用jrm2 equivelant。我不是最伟大的编码器,我只需要这个特殊的东西..我显示的代码在java中工作,但j2me dosnt使用java.io.file类,所以我会怎么去上传文件? – brux 2010-06-27 23:33:53