Home Answers Viewqa Java-Beginners java - file delete

 
 


babu
java - file delete
1 Answer(s)      4 years and 8 months ago
Posted in : Java Beginners

View Answers

September 17, 2008 at 11:00 AM


hi,

You can use following code to delete a file from the folder


import java.io.File;

public class DeleteFile {
public static void main(String[] args) {
String fileName = "C:\\file2\\Hello.txt";
File file = new File(fileName);

if (!file.exists())
System.out.println("File not found");

if (file.isDirectory()) {
String[] files = file.list();
if (files.length > 0)
throw new IllegalArgumentException(
"Delete: directory not empty: " + fileName);
}
boolean success = file.delete();
if (success){
System.out.println("File deleted successfully");
}
}
}


Thanks









Related Pages:
delete jsp
delete jsp  <%@ page language="java" contentType="text/html...; charset=ISO-8859-1"> <title>Delete Student</title> </head>...;/Controller"> <input type="hidden" name="page" value="delete"/> <
Java: Delete Blanks - Solution
Java: Delete Blanks - Solution See Exercise - Delete Blanks. Solution 1 - Using charAt public static String deblank(String s) { String result = ""; for (int i=0; i<s.length(); i++) { if (s.charAt(i
Delete Internet Explorer History in java program
Delete Internet Explorer History in java program  code for Delete Internet Explorer History in java program
DELETE
DELETE   I AM DOING IT IN MYSQL. DELETE FROM EMP WHERE SAL>(SELECT SAL FROM EMP WHERE ENAME='MILLAR') AND ENAME='ALLEN'; THIS IS GIVING THE FOLLOWING ERROR Error Code : 1093 You can't specify target table 'EMP
HTTPClient Delete Method program ( for REST API to delete a user )
HTTPClient Delete Method program ( for REST API to delete a user )  HI Friends, I am trying a HTTP delete method for creating REST API in java. can any one provide me a HTTPClient Delete method program for reference. Please
delete
delete  how delete only one row in the database using jsp.database... type="button" name="edit" value="Delete" style="background-color:red;font-weight... = conn.createStatement(); st.executeUpdate("DELETE FROM employee WHERE empid
How to delete line starting with a letter in java Regex?
How to delete line starting with a letter in java Regex?  Hi, i 'm trying to code with regex and java. i want to know how it's possible to delete lines which starts with a letter like G or g in a text. i tried
delete a node from singly linked list in java
delete a node from singly linked list in java  Write a program(in java), if given a pointer to a node (not the tail node) in a singly linked list, delete that node from the linked list.   could you tell your question
Exercise - Delete Blanks
Java: Exercise - Delete Blanks Write a method to delete all blanks from its parameter. The method signature is public static String deblank(String s...) deblank("I'm feeling fine.") returns "I'mfeelingfine." Delete Blanks
Adding checkbox in table using that delete table rows
Adding checkbox in table using that delete table rows  I need coding... that checkbox select more than than one rows,and using delete button i want to delete the selected rows using swing in java
Java App - Add, Delete, Reorder elements of the buttons
Java App - Add, Delete, Reorder elements of the buttons  Hello, I'm developing a Java application. I created this interface with MockupScreens... on "Element N" Button. He can too delete an element or change the order
Insert and Delete an element in between an array
Insert and Delete an element in between an array In this section, you will learn how to insert and delete an element in between an array. For this purpose, we have created two separate methods for inserting and deleting an element
Delete image from folder - JSP-Servlet
Delete image from folder  Dear All, i used some coding... some time its burden for server. so dear friends i want to delete that image when user will logout using java code. anybody having idea about then please
Delete a Column from a Database Table
\jdbc\jdbc\jdbc-mysql>java DeleteColumn Delete columns example... Delete a Column from a Database Table   ... to delete a column from a database table. We are not going to create a new table
JDBC Delete Row In Table Example
JDBC Delete Row In Table Example : In this tutorial we will learn how delete... or more specific  row delete from table that follow any given condition...  Mysql query  "DELETE FROM user where user_id=1 "  
Delete Account
Delete Account  How to delete account
Add Edit And Delete Employee Information
, edit and delete the Employee's information from the database using java swing... Add Edit and Delete Employee Information Using Swing  ... updated. In the third tab, we have allowed the user to delete the particular employee
JDBC Batch Example With SQL Delete Statement
JDBC Batch Example With SQL Delete Statement: Learn How to use delete MySql statement with JDBC Batch processing. First of all, we will create a java class...() as: connection.setAutoCommit(false); 3. Create SQL delete statement for save data
To delete post
To delete post  How can I delete my old post answer. I've posted 2 same answers by mistake
JDBC Delete All Rows In Table Example
JDBC Delete All Rows In Table Example:  In this tutorial provide...;  driver and java class "DeleteAllRows" that import all related... query and   execute. There use mysql query "DELETE FROM user"
How to delete and update from Jtable cell in swing app
How to delete and update from Jtable cell in swing app  Hii Sir... on delete button on selecting particular row which has to be deleted then last row... the database . I want to remove and delete the same row which is selected for the dletion
delete row
delete row  how to delete row using checkbox and button in php...="delete" > <table width="100%" border="1"> <tr><td>...;/table> <input type="submit" name="delete" value="delete" /> <?php
delete record
delete record  how to delete record using checkbox and button in php   We are providing you the jsp code that displays the database table...=conn.createStatement(); for(int a=0;a<10;a++){ st.executeUpdate("delete from book where
How to insert or delete records in MS access database using jsp - JSP-Servlet
How to insert or delete records in MS access database using jsp  Hi friends please provide me a solution that i insert or delete record from a database using java server pages. I used the microsoft access 2003 database. PlZ
delete an entry using JavaScript
delete an entry using JavaScript  How to delete an entry using JavaScript
delete() method of hibernate
delete() method of hibernate  Define the use of delete() method of hibernate? Example
delete javascript object
delete javascript object  How to create and delete an object in JavaScript
What is the Delete Statements in SQL?
What is the Delete Statements in SQL?  What is the Delete Statements in SQL?   Hi, Here is the answer, Delete statement in SQL is used to delete partial/all data. Especially delete statement is useful in case
how to delete a letter in a word?
how to delete a letter in a word?  how to delete a letter in a word? for example if i enter= roseindia, i want to delete 's', then output= roeindia
php delete checkbox
php delete checkbox  How can i delete the data with multiple check boxes in PHP
insert and delete a row programmatically
insert and delete a row programmatically  How to insert and delete a row programmatically ? (new feature in JDBC 2.0
delete an item from database
delete an item from database  how to delete an item from the database using jsp
uitableviewcell delete button position
uitableviewcell delete button position  uitableviewcell delete button position - how can i set? Thanks in Advance
delete app from iphone
delete app from iphone  How to delete an existing app from itunes
insert and delete data in database
insert and delete data in database  insert and delete data in database from servlets through JDBC   Hi Friend, Please visit the following links: Insert Data Delete Data Thanks
sqlite database delete row
sqlite database delete row  How to delete row from SQLite Database?    NSString *updateSQL = [NSString stringWithFormat: @"DELETE FROM aListDB WHERE id='%@'",details.ids
Delete Query using HQL
Delete Query using HQL  Can we write 'AND' with 'WHERE' clause in delete query using HQL? For example: delete from table name where field1... is "delete from table where field1 = 'value1' and field2 = 'value2'.   Have
The DELETE Statement
The DELETE Statement       The DELETE statement is used to delete rows from a table. database will update...;       DELETE FROM table_name WHERE
Hibernate delete HQL - Hibernate
Hibernate delete HQL  Hi I am trying hibernate tutorial. But delete HQL tutorial not working properly. It gives null pointer exception. Query class has method executeUpate() & not executeUpdate
tree menu delete node
tree menu delete node  I have crated a tree menu having various sub nodes now i want to delete parent node and also want to delete sub nodes when... using url ....i have a problem when i perform a delete operation on parent node
Delete points from database
Delete points from database  I have a polygon on a web page and a delete button. The polygon is saved in the database in one table and in another... the delete button, the polygon in the webpage gets deleted as well as the polygon
how to delete a row in sql without using delete command.
how to delete a row in sql without using delete command.  how to delete a row in sql without using delete command. thanks in advance
JPA delete query - EJB
JPA delete query  Hi, I have an entity InvoiceItems.java. I want to delete all the records from the table. What will be the JPA query to delete... to achieve this: Query query = em.createQuery("delete from InvoiceItems o
Create Delete Trigger in SQL
Create Delete Trigger in SQL       Create Delete Trigger in SQL fire this trigger before the DELETE operation is executed. Understand with Example
delete query problem - Hibernate
delete query problem  SessionFactory fact = new Configuration... = sess. beginTransaction(); String hql = "delete from STUDENT where name = 'mitha... system properly. STUDENT is not mapped. [delete from STUDENT where name = 'mitha
FTP Server : Remove Directory
In this section you will learn how to delete directory on FTP server using java
Use of delete() method in hibernate.
Use of delete() method in hibernate.  Define the use of delete() method of hibernate?   Hibernate provide the facility to delete one row... department0_ where department0_.id=? Hibernate: delete from department where id
delete row using id
delete row using id  package pkg2; import org.hibernate.Query; import... = "delete from Insurance insurance where id = 2"; Query query = sess.createQuery...: delete [delete from pkg2.Insurance insurance where id = 2
uitableview manually delete row
uitableview manually delete row  uitableview manually delete row   NSMutableIndexSet *indexes = [NSMutableIndexSet indexSet]; [array removeObjectAtIndex:indexPath.row]; if(![array count]) [indexes addIndex

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.