Java delete file if exists

Ads
 

Java delete file if exists

Hi,

Hi how to delete file if exists?

I need example code of java delete file if exists.

Thanks

View Answers

August 21, 2012 at 5:03 PM

Hi,

following code can be used:

String tempFile = "C:/mydir/myfile.txt";
//Delete if tempFile exists
File fileTemp = new File(tempFile);
if (fileTemp.exists()){
    fileTemp.delete();
}

thanks

Ads









Related Tutorials/Questions & Answers:
Java delete file if exists
Java delete file if exists  Hi, Hi how to delete file if exists? I need example code of java delete file if exists. Thanks   Hi... if tempFile exists File fileTemp = new File(tempFile); if (fileTemp.exists
How to delete file in Java code?
How to delete file in Java code?  Hi, From my Java program I have to delete a file. How to delete file in Java code? Thanks   Hi, Java API provides methods for deleting a file in Java. You can use the delete
Advertisements
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 to delete .xlsx file in java?
How to delete .xlsx file in java?  Hello Sir, I am unable to delete .xlsx file using below code, What is wrong here? if(myFile != null && myFile.exists()    && myFile.canRead() &&
J2ME delete file - Java Beginners
J2ME delete file  How do i delete a textfile on a mobile phone using j2me?  Hi Friend, Please visit the following link: http://www.roseindia.net/j2me/ Hope that it will be helpful for you. Thanks
Check the File Exists in PHP Program
Check the File Exists in PHP Program  Hi, I trying to create a application to find or retrieve the existing files. So, Please help me or suggest any online reference that explain about the file exists function in PHP? Thanks
Delete a file from FTP Server
In this section you will learn how to delete file from FTP server using java
delete lines in the file
delete lines in the file   I am using a file as Input in program...The file contains round about 1,00,000 lines .My program after each iteration takes a data from that file at process it. My Question is when a particular data
delete lines in the file
delete lines in the file   I am using a file as Input in program...The file contains round about 1,00,000 lines .My program after each iteration takes a data from that file at process it. My Question is when a particular data
delete lines in the file
delete lines in the file   I am using a file as Input in program...The file contains round about 1,00,000 lines .My program after each iteration takes a data from that file at process it. My Question is when a particular data
I want to know the given class name exists in which jar file?
I want to know the given class name exists in which jar file?   I want to know the given class name exists in which jar file? C:\Program Files\IBM... the name of the jar file where 'com.rational.ft.util.debug' class exists
Video Tutorial: How to check if a folder exists in Java through a source code
How to check if a folder exists in Java through a source code Java is an all... facilities. Here is the video tutorial of "How to check if a folder exists in Java... can check if a folder exists or not in Java. A new Java project is created
Delete file or Directory
Delete file or Directory      ... or a directory by using a java program. We pass the file name or the directory name to which we want to delete. The given program deletes an existing file if the file
Delete and edit data in xml file using JSP
Delete and edit data in xml file using JSP   I want to know how to delete and edit data from an XML file by use of JSP. I have XML file having tasks... in the xml file,I want to delete and edit some tasks using task id then how can i do
C file delete example
C file delete example       This section illustrates you to delete a file in C. You can see in the given example that we want to remove the file HELLO.txt. For this, we have
java file handling
java file handling  enter string from keyboard and then read a file if this string is present in file then print message already exists else write this string to file
How to delete files in Java?
Delete a File using File Class Object       Delete a File using File Class Object In this section, you will learn how to delete a file
Delete specific lines from text in Java
Delete specific lines from text in Java  Hi, beginning in java, i'm trying to delete specific line from a text file. Ex: i want to delete data... number that i want to delete. how could it be possible with java. thanks a lot
How to delete excel file records using Store Procedure?
How to delete excel file records using Store Procedure?  Hi.. I have created one Excel file through stored procedure.Now I want to delete records or delete excel file. Thanks
Delete Internet Explorer History in java program
Delete Internet Explorer History in java program  code for Delete Internet Explorer History in java program
ile_exists php
ile_exists php  i have written a simple php code where i used the file_exists. But somehow it's not working. Please suggest Thanks
String file in to word file in java
String file in to word file in java  How to convert a String format notepad file into Ms word file in java
calling a java file in java
calling a java file in java  how to call a another java file in java
how to delete a jar file from mobile by using j2me program.
how to delete a jar file from mobile by using j2me program.  When i'll update a new version jar in mobile. Then i want to delete that old jar which is previously present in mobile. How to do
How to delete content of a log file from linux terminal?
How to delete content of a log file from linux terminal?  Hi, My... running queries. But first I want to delete the content of the /var/log/slow-queries.log file. Can anyone tell me how to do this? Thanks   Hi, Its
String file in to word file in java
String file in to word file in java  how to convert a String format word file into Ms Word file using java? please can anyone of you help me
Java IO File
Java IO File In this section we will discuss about the File class in Java... can also create a File to store the data. To create file in Java a class named... of this class a Java programmer can create a new file. File.createNewFile() method
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
java get file permission
java get file permission  How to check the get file permission in Java
Java code to convert pdf file to word file
Java code to convert pdf file to word file  How to convert pdf file to word file using Java

Ads