奇怪的mkdir()行为

时间:2018-05-06 10:13:38

标签: codenameone

我的代码一直运行良好,没有麻烦。我真的无法指出是否发生了后台更新并且我的代码被破坏了。我试图在设备上创建目录/文件,但它会引发错误。请参阅Logcat中的堆栈跟踪和我的代码。

    05-06 05:41:04.503 9015-9039/com.jajitech.xdata.mobile I/System.out: this is ee 43736017.collectordecision_templateVdjd
05-06 05:41:04.523 9015-9039/com.jajitech.xdata.mobile I/System.out: this is sent code 0
05-06 05:41:04.523 9015-9073/com.jajitech.xdata.mobile W/System.err: entry is Vdjd
05-06 05:41:04.903 9015-9039/com.jajitech.xdata.mobile W/System.err: mkdir failed: ENOENT (No such file or directory) : /data/user/0/com.jajitech.xdata.mobile/files/dataplat/entries/43736017.collector/decision_template/Vdjd/sent
    java.io.FileNotFoundException: /data/user/0/com.jajitech.xdata.mobile/files/dataplat/entries/43736017.collector/decision_template/Vdjd/sent/sent.jaji: open failed: ENOENT (No such file or directory)
05-06 05:41:04.933 9015-9039/com.jajitech.xdata.mobile W/System.err:     at libcore.io.IoBridge.open(IoBridge.java:452)
        at java.io.FileOutputStream.<init>(FileOutputStream.java:87)
        at java.io.FileOutputStream.<init>(FileOutputStream.java:127)
        at java.io.FileOutputStream.<init>(FileOutputStream.java:116)
        at com.codename1.impl.android.AndroidImplementation.createFileOuputStream(AndroidImplementation.java:5292)
        at com.codename1.impl.android.AndroidImplementation.openFileOutputStream(AndroidImplementation.java:5196)
        at com.codename1.io.FileSystemStorage.openOutputStream(FileSystemStorage.java:274)
        at com.jajitech.xdata.mobile.XDataMobile$22$1.run(XDataMobile.java:1771)
        at com.codename1.ui.Display.processSerialCalls(Display.java:1129)
        at com.codename1.ui.Display.edtLoopImpl(Display.java:1073)
        at com.codename1.ui.Display.invokeAndBlock(Display.java:1186)
        at com.codename1.ui.Display.invokeAndBlock(Display.java:1223)
        at com.jajitech.xdata.mobile.XDataMobile.prepareToSendToCloud(XDataMobile.java:1736)
        at com.jajitech.xdata.mobile.XDataMobile.lambda$NewDataEntry$17(XDataMobile.java:1457)
        at com.jajitech.xdata.mobile.XDataMobile$$Lambda$16.actionPerformed(Unknown Source)
        at com.codename1.ui.util.EventDispatcher.fireActionEvent(EventDispatcher.java:349)
        at com.codename1.ui.Button.fireActionEvent(Button.java:512)
        at com.codename1.ui.Button.released(Button.java:546)
        at com.codename1.ui.Button.pointerReleased(Button.java:650)
        at com.codename1.ui.Form.pointerReleased(Form.java:2903)
        at com.codename1.ui.Component.pointerReleased(Component.java:4178)
        at com.codename1.ui.Display.handleEvent(Display.java:2061)
        at com.codename1.ui.Display.edtLoopImpl(Display.java:1043)
        at com.codename1.ui.Display.mainEDTLoop(Display.java:961)
        at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:120)
        at com.codename1.impl.CodenameOneThread$1.run(CodenameOneThread.java:60)
        at java.lang.Thread.run(Thread.java:818)
    Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
        at libcore.io.Posix.open(Native Method)
        at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
        at libcore.io.IoBridge.open(IoBridge.java:438)
        ... 26 more

在下面找到第1771行的代码

char sep = FileSystemStorage.getInstance().getFileSystemSeparator();
            String dir = FileSystemStorage.getInstance().getAppHomePath() + sep + "dataplat"+sep+"entries"+sep+code+sep+section+sep+entry;
Display.getInstance().callSerially(new Runnable()
        {
            public void run()
            {
                if(isSilent == false)
                {
                    status.setMessage("Preparing to send...");
                    status.setShowProgressIndicator(true);
                    status.setIcon(createIcon(FontImage.MATERIAL_WORK));
                    status.show();
                    errorCode= "1594";
                }
                char sep = FileSystemStorage.getInstance().getFileSystemSeparator();
                String dir = FileSystemStorage.getInstance().getAppHomePath() + sep + "dataplat"+sep+"entries"+sep+code+sep+section+sep+entry;
                try
                {
                    FileSystemStorage.getInstance().mkdir(dir + sep + "sent"+sep);
                    errorCode= "1595";
             //Line 1771       OutputStream dest = FileSystemStorage.getInstance().openOutputStream(dir + sep + "sent" + sep + "sent.jaji");
                    TarOutputStream out = new TarOutputStream( new BufferedOutputStream( dest ) );
                    String entries[]  = FileSystemStorage.getInstance().listFiles(dir);

...

1 个答案:

答案 0 :(得分:1)

你需要逐个制作每个目录,直到你到达最后一个目录。这就是mkdir的工作原理而不是mkdirs