Загрузить файл через FTP с помощью Java ME - PullRequest
2 голосов
/ 28 июня 2010

Как я могу изменить следующий Java-код, чтобы он работал на J2RE (Java ME), поскольку в Java ME нет класса java.io.files: (

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

}

1 Ответ

2 голосов
/ 28 июня 2010

Если вы хотите открыть и прочитать файл, посмотрите на эти две ссылки

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

Вот примерраспечатать содержимое файла ...

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) {
   }
}
...