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




Have Programming Question? Ask it here!
 
 
 


manasa
java
1 Answer(s)      5 years and 10 months ago
Posted in : Java Beginners



Advertisement
View Answers

November 10, 2008 at 7:27 AM


Hi friend,


import java.io.*;
import java.io.File;

public class FileSecurityDemo {

private String fileName = null;

public FileSecurityDemo(String fName) {
this.fileName = fName;
}


// No-arg constructor

public FileSecurityDemo() {
this("defaultFile.txt");
}


// Creates the object file.

public void createFile() {

try {

File fileHandler = new File(fileName);

if (fileHandler.createNewFile()) {
System.out.println("File (" + fileName + ") did not exist and was created.\n");
} else {
System.out.println("File (" + fileName + ") already exists.\n");
}

} catch (IOException e) {
System.out.println("Could not create file: " + fileName);
e.printStackTrace();
}

}

/**
* Deletes the object file.
*/
public void deleteFile() {

File fileHandler = new File(fileName);

boolean success = fileHandler.delete();

if (success) {
System.out.println("File (" + fileName + ") was successfully deleted.\n");
} else {
System.out.println("File (" + fileName + ") was not successfully deleted.\n");
}

}

public String getFileName() {
return fileName;
}

public static void main(String[] args) {
FileSecurityDemo fsd = new FileSecurityDemo("file1.txt");
fsd.createFile();
fsd.deleteFile();
}

}


---------------------------

Thanks.


Related Tutorials/Questions & Answers:
java
java   What is ?static? keyword
java
java  hi im new to java plz suggest me how to master java....saifjunaid@gmail.com
Advertisements
java
java  1.what type of inheritance supported in java. 2.what is the advantage of java over C++.   Hi Friend, Java supports following... inheritance Advantages of Java over C++: 1)Java is pure object oriented
java
java  i need to draw a binary tree traversal in java applet
Java
Java   What is the immediate superclass of the Dialog class
java
of java connection to the database to the java program   Hello Friend, Please visit the following link: Java Database Connectivity Here you will find several examples related to java database connectivity. Thanks
java
java  why we pass reference as a parameter in any java method
java
java  how to learn d java in easy way   Hi Friend, Please visit the following link: Java Tutorials Thanks
java
java  please any one give me idea for how to learn applet in java and then any one tell me concept for applet in java
JAVA
JAVA  Name Explanation about Java....   Hi Friend, Please clarify your problem. Thanks   Abbreviation of JAVA
JAVA
JAVA  If anybody know the abbreviation of JAVA....   JAVA is a full functioning programming structure by Sun Microsystems there is no abbreviation, and it is not the abbreviation (or acronym) of anything
java
, visit the following links: http://www.roseindia.net/java/master-java/java-left-shift.shtml http://www.roseindia.net/java/master-java/java-right-shift.shtml
java
java  can we implement two main class in java?   Hi Friend, A java class should have only one main method. Thanks
Java
Java  How to install java on linux ubuntu?   Hi Friend, Please visit the following links: http://www.roseindia.net/linux/linux-java-install.shtml http://www.roseindia.net/linux/tutorial/installingjdk5onlinux.shtml
java
java  write a programe in java such as child thread excutes 3 times more than main thread
JAva
JAva   how to make a class final without using final keyword
java
java  write a programe in java such as child thread excutes 3 times more than main thread
java
java  where i write java programme and how do i execute the programme
Java
Java  java program to get output on the basis of users choice of switch statement perform operations addition, subtraction and multiplication of matrix
java
java  hi all i have a problem ,i want to sotre form data in table with foreign key in java ,please help me  Hi,Are you developing desktop or JSP application?Thanks
java
java  What is the purpose of Void class?  The Void class is an uninstantiable placeholder class to hold a reference to the Class object representing the Java keyword void
java
java  I need to draw a Binary tree using Inorder traversal algorithm.. in java applets using rectangles and ellipse objects.. can anyone help me about
java
inheritance. Java does not support multiple inheritance but the multiple inheritance...://www.roseindia.net/java/language/inheritance.shtml
java
java  Hi friends and how are you? i have a problem i need to write a java program which has a two java packages, one has the interface and the other has classes, with each class calculating the conversion of the South african
java
java  Pls help me with project or pls give me guide lines to this: Hi friends and how are you? i have a problem i need to write a java program which has a two java packages, one has the interface and the other has classes
java
java  What is DriverManager?  The JDBC Driver Manager is a very important class that defines objects which connect Java applications to a JDBC driver. Usually Driver Manager is the backbone of the JDBC architecture
java
java  <p>java program to find short form of namefor eg . sudhir kumar tiwari output should be s.k tiwari</p>  Hi Friend, import java.util.*; public class InitialName { public static void main
Java
Java  Hi I need help to edit values in database into jsp page textboxes, This is my code: editdata.jsp <%@ page language="java" import="java.util.*;"%> <%@ page language="java" import="java.sql.*"%> <
Java Fundamentals - Java Beginners
Java Fundamentals  What is the difference between Java Bean and Java Class
java - Java Interview Questions
Java Programming  What is Java Programming language
java
/TR/html4/loose.dtd"> <%@ page language="java" import="java.sql.*"%> <title>
Java - Java Interview Questions
Java  Questions on Java
java+cts - Java Beginners
java+cts  4100156952
core java - Java Beginners
core java  i want to get java projects in core java
java - Java Magazine
Java string array declaration  How to declare a string array in Java
Java - Java Beginners
Java enum class tostring  An example of Java enum class tostring
Java Gui - Java Beginners
Java Gui  HOW TO ADD LINK LABELS IN JAVA PROGRAMMES
Java GUI - Java Beginners
Java GUI  HOW TO ADD ICONS IN JAVA GUI PROGRAMMES
JAva Projects - Java Magazine
JAva Projects  I need Some Java Projects
Java - Java Beginners
Java   HOW TO MAKE 3D GAMES IN JAVA
java on linux - Java Beginners
java on linux  How to compile and execute java applications in linux
Java Questions - Java Beginners
Java Questions  Can we make 3d games in java
Java tools - Java Beginners
Java tools  how can we create a tool using java
java - Java Beginners
Java GUI Builder software  Java GUI Builder software
java threads - Java Beginners
java threads  What is Thread in Java and why it is used
java - Java Interview Questions
java  how to learn java
java - Java Beginners
java  what are the logics of java
java - Java Beginners
Java virtual machine  What is java virtual machine?  Hello,Please check http://www.roseindia.net/help/java/f/java-foreach.shtmlThanks
java - Java Beginners
Java keywords with examples  Java keywords with example to learn Java programming fast
java - Java Beginners
Java coding standards for developors  What is the java coding standards for Java application developers
 

 

 

DMCA.com