Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Java lock file or folder.

Have Programming Question? Ask it here!
 
 
 


Steve
Java lock file or folder.
1 Answer(s)      a year and 9 months ago
Posted in : Java Beginners


Is it possible to create a desktop application to lock or encrypt file or folder in windows by using java code?? if possible can provide some reference?? because i can't find it...

thanks.


Advertisement
View Answers

November 27, 2012 at 5:51 PM


Here is an example of file locking.

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

public class FileLockExample {
        public static void main(String[] args) throws Exception {
                try {
                        RandomAccessFile file = new RandomAccessFile("C:/file.txt", "rw");
                        FileChannel fileChannel = file.getChannel();
                        FileLock fileLock = fileChannel.tryLock();
                        if (fileLock != null) {
                                System.out.println("File is locked");
                                accessFile();
                        }
                } catch (Exception e) {
                }
        }

        public static void accessFile() {
                try {
                        String line = "";
                        BufferedReader br = new BufferedReader(
                                        new FileReader("C:/file.txt"));
                        while ((line = br.readLine()) != null) {
                                System.out.println(line);
                        }
                } catch (Exception e) {
                        System.out.println(e);
                }
        }
}


Related Tutorials/Questions & Answers:
Java lock file or folder.
Java lock file or folder.  Is it possible to create a desktop application to lock or encrypt file or folder in windows by using java code?? if possible can provide some reference?? because i can't find it... thanks
Java file lock
Java file lock In this section, you will learn how to lock a file. The behavior of the file lock is platform-dependent. The file lock is advisory on some platforms, means unless an application checks for a file lock
Advertisements
Java lock
Java lock  Can a lock be acquired on a class
Java lock
Java lock  Can a lock be acquired on a class
copy file from folder to folder - Java Beginners
copy file from folder to folder   my requirement is I need to copy xml files from one folder to another my source file contains the field filename.... Suppose in the source file, file name is goodfile1.xml source folder
Java object's lock
Java object's lock  What is an object's lock and which object's have locks
Java thread lock
Java thread lock  What happens when a thread cannot acquire a lock on an object
How to upload and save a file in a folder - Java Beginners
How to upload and save a file in a folder  Hi How to upload and save a file in a folder? for example Agreement.jsp File: So when user browses the file and enters the submit button the respective file should
Image is in same folder where the java file is located - Swing AWT
Image is in same folder where the java file is located  dear sir It is there in the same folder..means the photograph.jpg file is created in the same folder where my java file is present... wat I should do sir
Folder in Java.
Folder in Java.  I have any problem how to make Folder in java program? Can Anybody help me in this part
code for recently created file from a folder in java - Java Beginners
code for recently created file from a folder in java  how to get the recently created file from a folder in java?  Hi friend, Code...=""; try { File file = new File(dirname); if(file.isDirectory
how to download a file from a folder??
how to download a file from a folder??  i can upload any kind of files to a folder, and only the path of the file is saved into the database, now how a client can download the file from my folder. pls provide me the jsp code
Getting the modification date and time of file or folder in Java
C:\nisha>java GetDirectoryAndFileModifiedTime Enter file or directory name in proper format to get the modification date and time : myfile.txt File name : myfile.txt File modification date
How to make one waiting thread for lock - Java Beginners
to java. Can u explain about thread concept.How i know one thread is locked, and how can i force or acquire another thread for lock . Finally how to know thread is released from lock. Explain types of lock(like method level and block level
Zipping folder - Java Beginners
to zip a user selected folder . this folder may contain any number of folder and sub folders. i saw an example in this site showing , how to zip a folder, i executed... solve this.. zipping folder and all of its files and sub folders. thanking
image save to folder in java
image save to folder in java  Hi, I am working with java. In my application i want to give facility to user to add and change image. I use open... folder and that path stored into database, for furhter retrivation. Please guide me
Zipping folder - Java Beginners
to zip a user selected folder . this folder may contain any number of folder and sub folders. i saw an example in this site showing , how to zip a folder, i executed... solve this.. zipping folder and all of its files and sub folders. thanking
java client server program for playing video file(stored in folder in the same workspace) using swings
java client server program for playing video file(stored in folder in the same... a client server program to play a video file, when I run both client and server... file name"); l.setBounds(50, 30, 100, 50); getContentPane().add(l
java client server program for playing video file(stored in folder in the same workspace) using swings
java client server program for playing video file(stored in folder in the same... a client server program to play a video file, when I run both client and server... file name"); l.setBounds(50, 30, 100, 50); getContentPane().add(l
java client server program for playing video file(stored in folder in the same workspace) using swings
java client server program for playing video file(stored in folder in the same... a client server program to play a video file, when I run both client and server... file name"); l.setBounds(50, 30, 100, 50); getContentPane().add(l
java client server program for playing video file(stored in folder in the same workspace) using swings
java client server program for playing video file(stored in folder in the same... a client server program to play a video file, when I run both client and server... file name"); l.setBounds(50, 30, 100, 50); getContentPane().add(l
java program to copy the contents of one folder to another folder
java program to copy the contents of one folder to another folder  java program to copy the contents of one folder to another folder   Have a look at the following link: Java Copy one folder to another
lock on a class
lock on a class  hello, Can a lock be acquired on a class?   hiii,, Yes, a lock can be acquired on a class. This lock is acquired on the class's Class object
how to backup files and folder with Java
how to backup files and folder with Java  Does anyone know to create a backup with java?. backup files and folders from my computer to an external... filename, String... content) throws IOException{ File
write file in aplication folder with out giving full path - WebSevices
write file in aplication folder with out giving full path  i have a simple java class by the help of this java class i want to write file in application folder with out giving full path like c:/data/aa
how to upload a file of apk format in a folder from servlet
how to upload a file of apk format in a folder from servlet  How to upload a file of apk format to a folder from servlet, i am trying to do, its getting uploaded as .zip file and not apk file
difference between lock and synchronization
difference between lock and synchronization  Hi, I am new in java please anyone tell me difference between lock and synchronization in java. its urgent. Thank in advance   Please visit the following link: Lock
files that are present in any folder , how to make it clickable downloadble file in php
files that are present in any folder , how to make it clickable downloadble file in php   files that are present in any folder , how to make it clickable downloadble file in php
Spring 3.2 MVC, Upload File in a specific folder
In this Spring 3.2 MVC tutorial, you will learn about uploading file in a specified folder
how can i open pdf file in assest folder in android application?
how can i open pdf file in assest folder in android application?  thanks
Java- Save Image into project folder in web application
Java- Save Image into project folder in web application  I have a requirement of saving the image into project folder .. which is a web application. I am not able to figure out how to find the absolute path of my folder which I
How to delete file in java ?
How to delete file in java ? In this section we will learn how to write a program to delete a file in java. You can delete the file or folder, java File.... Now, here is the code to delete a file in java. import java.io.File; public
How I Choose a folder - Java Interview Questions
do not explain clearly my question. I know how I get files from a folder. My question How I select a folder. From this selected folder i get the files. I know how I get files but the problem How I choose a folder. Thanks
How can store image in server folder when deployed with a .war file?
How can store image in server folder when deployed with a .war file?  Hi all; When I am using application.getRealPath() , it return null when deployed with a .war file and when I use hard code it shows syntax error or path
how to upload multiple files in jsp and saving the path in database and the file in folder
how to upload multiple files in jsp and saving the path in database and the file in folder  how to upload multiple files in jsp and saving the path in database and the file in folder I have created a form for the upload of files
Java Util Zip. Zip files/folders inside a folder, without zipping the original source folder.
Java Util Zip. Zip files/folders inside a folder, without zipping the original... srcFile, ZipOutputStream zip) throws Exception { File folder = new File... { File folder = new File(srcFolder); for (String fileName : folder.list
create folder chooser - Java Server Faces Questions
create folder chooser  I don't know how to create a browser folder( to save file download, for instance, not file chooser), please help me,(use swing...() { try { bi = ImageIO.read(new File("node.jpg")); w
Java get Folder Size
Java get Folder Size     ... File(folder)) Here is the code of GetFolderSize.java...();   long fileSizeByte=size.getFileSize(new File(folder
Zip Folder Using Java
in this folder are zipped by using java. Here we will learn how to compress files... objects of File class. In first object we are pass the name of  the folder... Zipping a Folder      
How to access the image file from project folder itself while writing to pdf using itext?
How to access the image file from project folder itself while writing to pdf... to search for the image in the domain folder of the glassfish location.But i want it to pick it up from the project folder itself.Because later i deploy the project
How to open excel sheet when excel file is placed in some folder in desktop
How to open excel sheet when excel file is placed in some folder in desktop  How to open an excel sheet using windows.open in IE... I am getting an error msg that the path is not correct.. But i have specified the correct path
Create new file in java
in java File class representing the files and folder pathnames by location. With File class we create files and directories. Java File represents actual...Create new file in java We are going to discuss how to create new file in java
How to copy files from one folder to another based on lastmodified date - Java Beginners
How to copy files from one folder to another based on lastmodified date  I have to make a simple utility to copy files from a folder to another folder in the same hierarchy, without overwriting the existing.  hiimport
What is an object's lock and which object's have locks?
What is an object's lock and which object's have locks?   Hi, What is an object's lock and which object's have locks? Thanks
Java sdk/java poi hssf code to creat excel with folder structure,( i,e folders, subfolders and childrens )
Java sdk/java poi hssf code to creat excel with folder structure,( i,e folders... in the excel file . To be precise, am working on Java sdk of business objecsts . i need some help in getting folder structure using this java . Folder
java program to take the backup of folders and copy the folder in different location without deleting the existing one
java program to take the backup of folders and copy the folder in different location without deleting the existing one  java program to take... the existing one   Have a look at the following link: Java Copy one folder
Java Thread HoldsLock
Java Thread HoldsLock In this tutorial, you will learn how to lock a thread with example in Java. Thread HoldsLock  : It is easy to use...): This method returns true if the current thread holds the monitor lock
create folder
create folder  what code we should write as a web application that it create an empty folder on client's desktop
how to read 100 text files from a folder or directory and write the data into a single file.using java programming?
how to read 100 text files from a folder or directory and write the data into a single file.using java programming?  i have multiple(app..100) text... the files and write them into a single file..the target file should have the 1st
How to copy files from one folder to another based on lastmodified date - Java Beginners
Copy files from one folder to another  How to copy files from one folder to another based on lastmodified date
 

 

 

DMCA.com