开发者

Upload a file Via FTP Using Java ME

How can I开发者_如何学Go modify the following java code so that it works on J2RE(Java ME) as there is no java.io.files class in 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();
    }

}


If what you want to do is to open and read a file then look at these two links

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

Here is a sample to print the contents of a file...

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜