how to make a file/folder hidden/unhidden in J2ME

2019-03-03 20:18发布

Currently am working on a project where I need to hide my files/folder on sd card..?? I was wondering is it possible to hide and then latter unhide a file/folder..?? I got this from searching which helps you to create a text file in Images under Gallery

 import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.io.file.*;
import javax.microedition.io.*;
import java.io.*;

public class WriteMIDlet extends MIDlet implements CommandListener {
private TextBox textbox;
private String photos = "fileconn.dir.photos";
private Command saveCommand;
private Command exitCommand;
private String path;

public void startApp() {
    textbox = new TextBox("WriteMIDlet", "", 1000, TextField.ANY);
    saveCommand = new Command("Save", Command.SCREEN, 1);
    exitCommand = new Command("Exit", Command.EXIT, 1);
    textbox.addCommand(saveCommand);
    textbox.addCommand(exitCommand);
    textbox.setCommandListener(this);
    Display.getDisplay(this).setCurrent(textbox);
    path = System.getProperty(photos);
}

public void pauseApp() {
}

public void destroyApp(boolean unconditional) {
}

private void saveFile(String path, String name) {
    try {
        String url = path + name;
        String string = textbox.getString();
        byte data[] = string.getBytes("UTF-8");
        FileConnection fconn = (FileConnection)Connector.open(url, Connector.READ_WRITE);
        if (!fconn.exists()) {
            fconn.create();
        }
        OutputStream ops = fconn.openOutputStream();
        ops.write(data);
        ops.close();
        fconn.close();
    }
    catch (IOException ioe) {
        System.out.println("IOException: "+ioe.getMessage());
    }
    catch (SecurityException se) {
        System.out.println("Security exception:" + se.getMessage());
    }
} 

public void commandAction(Command c, Displayable d) {
    if (c == saveCommand) saveFile(path, "readme.txt");
    if (c == exitCommand) this.notifyDestroyed();
}    

}

Like wise is there any way we could create a folder in sd card and then hide/unhide it according to need..?? Also can we retrieve hidden folders ..??

Please help...

标签: java-me
1条回答
成全新的幸福
2楼-- · 2019-03-03 20:36

You can call

fconn.setHidden(true);

but... according to documentation:

The attribute is applied to the file on the actual file system immediately upon invocation of this method if the file system and platform support it. If the file system doesn't support a hidden attribute, this method is ignored and isHidden() always returns false.

查看更多
登录 后发表回答