2013-07-05 63 views
0

现在我正在开发一个项目,我需要在SD卡中创建一个能够完成的文件夹。此外,我需要根据需要隐藏/取消隐藏它。该代码在仿真器上正常工作,但不在设备中,这是我的代码出了什么问题?错误:文件不存在

public class FolderCreate extends MIDlet { 
    private Form form; 
    private Display display; 
    FileConnection fc; 
    String path; 

     public void startApp() {   

     form = new Form("Hello World"); 
     String msg = "Hello World!!!!!!!"; 
     form.append(msg); 
     display = Display.getDisplay(this); 
     display.setCurrent(form); 
    System.out.println("WWWW");   
     try { 
      path = System.getProperty("fileconn.dir.memorycard"); 
      System.out.println("Path : "+path+"/sample"); 
       fc = (FileConnection)Connector.open(path+"/ABCD/"); 
       if(!fc.exists()) 
       { 
        fc.mkdir(); 
        System.out.println("directory created");     
       }    

     } catch (IOException e) { 
       // TODO Auto-generated catch block 
       //System.out.println("ERROR "+e.getMessage()); 
      Alert alert = new Alert("Alert"); 
      alert.setString(e.getMessage()); 
      display.setCurrent(alert); 
     } 
     try 
     { 
      //fc = (FileConnection)Connector.open(path+"/sample/"); 
      if(fc.isHidden()) 
       { 
        fc.setHidden(false); 
       } 
      else{ 
        fc.setHidden(true); 
      } 
     fc.close(); 
     } 
     catch (Exception e) 
     { 
      Alert alert = new Alert("Alert2"); 
      alert.setString(e.toString()); 
      display.setCurrent(alert); 
     } 




    } 

    public void pauseApp() { 
    } 

    public void destroyApp(boolean unconditional) { 
     System.out.println("Destroyed"); 
     notifyDestroyed(); 
    } 
} 

错误时得到的是:java.io.IOException:文件不存在

回答

-1

,我认为你是在下面的行做的错误,

path = System.getProperty("fileconn.dir.memorycard"); 

当你用手机和SD卡工作您应该使用e:驱动器参照SD卡如下,

path = file:///e:/<folder-name>/ 
+0

此方法(addind“e:”)不保证能够与所有设备一起使用。 :( –

0

检查path是否以"file://"开头。如果不是,请添加后缀。

path = System.getProperty("fileconn.dir.memorycard"); 
if (path != null && !path.startsWith("file://")) { 
    path = "file://" + path; 
} 
相关问题