views:

54

answers:

1

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

}
+2  A: 

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) {
   }
}
Romain Hippeau
I actually am developing a client side app and I need to integrate this feature, the link you provided is an ftp client not an api or class for developing aps, and also its commercial :<
brux
@brux Now I am confused as to what you need. Are you looking for an FTP client API for J2ME ? If so, or if not please clarify your question, it is very vague as to what you are asking.
Romain Hippeau
thanks for your reply Romain.Basically I want to know how to subsitiute the java.io.files part so that it uses the jrm2 equivelant. Im not the greatest coder, I just need this particular thing..the code I show works in java, but j2me dosnt use the java.io.file class, so How would I go about uploading the file?
brux
@brux - I updated my answer, hope this helps.
Romain Hippeau
sorted mate, this looks like what i need! Thank you so much.
brux