How to set a password for a folder programmatically in android

你说的曾经没有我的故事 提交于 2019-12-06 04:11:00

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