How to set a password for a folder programmatically in android

喜欢而已 提交于 2020-01-14 02:45:26

问题


Is there a way to set a password for a folder programmatically?


回答1:


The best solution I can think of is to do it like you do in java: An example in this link describes as follows:

import java.io.*;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;

public class FileLockTest {

    public static void main(String[] args) throws Exception {

        RandomAccessFile file = null;
        FileLock fileLock = null;
        try
        {
            file = new RandomAccessFile("FileToBeLocked", "rw");
            FileChannel fileChannel = file.getChannel();

            fileLock = fileChannel.tryLock();
            if (fileLock != null){
                System.out.println("File is locked");
                accessTheLockedFile();
            }
        }finally{
            if (fileLock != null){
                fileLock.release();
            }
        }
    }

    static void accessTheLockedFile(){

        try{
            FileInputStream input = new FileInputStream("FileToBeLocked");
            int data = input.read();
            System.out.println(data);
        }catch (Exception exception){
            exception.printStackTrace();
        }
    }
}


来源:https://stackoverflow.com/questions/14494271/how-to-set-a-password-for-a-folder-programmatically-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!