check if a file is hidden java program

The isHidden() method of File class is used to check if a file is hidden in java. It returns true if the specified file is hidden else return false. Example: package com.w3spoint;   import java.io.File;   public class HiddenFileTest { public static void main(String args[]){ try { //File File file = new File("D:/Test files/newTest.txt"); //Check … Read more

Categories IO

make a read only file writable java

The setWritable() method of File class is used to make a read only file writable in java. It takes a boolean value as a parameter. Example: package com.w3spoint;   import java.io.File;   public class WritableFileTest { public static void main(String args[]){ try { //File File file = new File("D:/Test files/newTest.txt"); //Check the file is writable … Read more

Categories IO

check if file is writable java program

The canWrite() method of File class is used to check if file is writable java. It returns true if the specified file is writable else return false. Example: package com.w3spoint;   import java.io.File;   public class WritableFileTest { public static void main(String args[]){ try { //File File file = new File("D:/Test files/newTest.txt"); //Check the file … Read more

Categories IO

make a file read only java

The setReadOnly() method of File class is used to make a file read only in java. It returns true is the operation is successful else return false. Example: package com.w3spoint;   import java.io.File;   public class ReadOnlyFileTest { public static void main(String args[]){ try { //File File file = new File("D:/Test files/file 3.txt"); //Convert the … Read more

Categories IO

rename file in java program

The renameTo() method of File class is used to rename the existing file in java. It returns true if the specified file is renamed successfully otherwise returns false. Example: package com.w3spoint;   import java.io.File;   public class RenameFileTest { public static void main(String args[]){ try { //File to rename File oldFile = new File("D:/Test files/file … Read more

Categories IO

delete file in java program

The delete() method of File class is used to delete the existing file in java. It returns true if the specified File deleted successfully otherwise returns false. Example: package com.w3spoint;   import java.io.File;   public class DeleteFileTest { public static void main(String args[]){ try { //Specify the file name and path File file = new … Read more

Categories IO

write byte content to a file java program

Example: package com.w3spoint;   import java.io.File; import java.io.FileOutputStream; import java.io.OutputStream;   public class WriteByteToFileTest { public static void main(String args[]){ OutputStream opStream = null; try { String strContent = "Test Content"; byte[] byteContent = strContent.getBytes(); File myFile = new File("D:/Test files/test.txt"); //check if file exist, //otherwise create the file before writing if (!myFile.exists()) { myFile.createNewFile(); … Read more

Categories IO

write string content to a file java

Example: package com.w3spoint;   import java.io.File; import java.io.FileOutputStream; import java.io.OutputStream;   public class WriteByteToFileTest { public static void main(String args[]){ OutputStream opStream = null; try { String strContent = "Test Content"; byte[] byteContent = strContent.getBytes(); File myFile = new File("D:/Test files/test.txt"); //check if file exist, //otherwise create the file before writing if (!myFile.exists()) { myFile.createNewFile(); … Read more

Categories IO

delete temporary file java program

Example: package com.w3spoint;   import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter;   public class TempFileDelete { public static void main(String args[]){ File tempFile = null; BufferedWriter writer = null; try { tempFile = File.createTempFile("TempFile", ".tmp"); writer = new BufferedWriter(new FileWriter(tempFile)); writer.write("Test Content"); } catch (Exception e) { e.printStackTrace(); } System.out.println("Stored data in temporary file."); tempFile.deleteOnExit(); System.out.println("Temporary … Read more

Categories IO

store data into temporary file java

Example: package com.w3spoint;   import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.Writer;   public class WriteStringToFileTest { public static void main(String args[]){ BufferedWriter bufferedWriter = null; try { String strContent = "Test Content"; File myFile = new File("D:/Test files/test.txt"); //check if file exist, //otherwise create the file before writing if (!myFile.exists()) { myFile.createNewFile(); } Writer … Read more

Categories IO