本文整理汇总了Java中java.io.File.delete方法的典型用法代码示例。如果您正苦于以下问题:Java File.delete方法的具体用法?Java File.delete怎么用?Java File.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.File
的用法示例。
在下文中一共展示了File.delete方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deleteCache
import java.io.File; //导入方法依赖的package包/类
public boolean deleteCache(String urlPath){
String filePathMd5 = stringToMD5(urlPath);
if(filePathMd5 == null){
return false;
}
if(mCacheFileDir == null){
mCacheFileDir = Environment.getExternalStorageDirectory().toString() + "/ahttp/";
}
File fileDir = new File(mCacheFileDir);
if(!fileDir.isDirectory() || !fileDir.exists()){
return false;
}
filePathMd5 = mCacheFileDir + filePathMd5 + ".data";
File file = new File(filePathMd5);
if(file.exists()){
file.delete();
}
return true;
}
示例2: if
import java.io.File; //导入方法依赖的package包/类
public static int sletFilerÆldreEnd(File mappe, long tidsstempel) {
int antalByteDerBlevSlettet = 0;
int antalFilerDerBlevSlettet = 0;
File[] files = mappe.listFiles();
if (files != null) {
for (File file : files) {
if (file.lastModified() < tidsstempel) {
antalByteDerBlevSlettet += file.length();
antalFilerDerBlevSlettet++;
file.delete();
}
}
}
Log.d("sletFilerÆldreEnd: " + mappe.getName() + ": " + antalFilerDerBlevSlettet + " filer blev slettet, og " + antalByteDerBlevSlettet / 1000 + " kb frigivet");
return antalByteDerBlevSlettet;
}
示例3: rotate
import java.io.File; //导入方法依赖的package包/类
/**
* Rotate the set of output files
*/
private synchronized void rotate() {
Level oldLevel = getLevel();
setLevel(Level.OFF);
super.close();
for (int i = count-2; i >= 0; i--) {
File f1 = files[i];
File f2 = files[i+1];
if (f1.exists()) {
if (f2.exists()) {
f2.delete();
}
f1.renameTo(f2);
}
}
try {
open(files[0], false);
} catch (IOException ix) {
// We don't want to throw an exception here, but we
// report the exception to any registered ErrorManager.
reportError(null, ix, ErrorManager.OPEN_FAILURE);
}
setLevel(oldLevel);
}
示例4: testDownloadCustomFilename
import java.io.File; //导入方法依赖的package包/类
@Test
public void testDownloadCustomFilename() throws Exception {
Mockito
.doReturn(Helpers.createRawCall("text/plain", "Test content"))
.when(Networking.getCdnService())
.get("handle", null, null);
Config config = new Config("apikey");
FileLink fileLink = new FileLink(config, "handle");
File file = fileLink.download("/tmp/", "filestack_test_filelink_download.txt");
Assert.assertTrue(file.isFile());
if (!file.delete()) {
Assert.fail("Unable to cleanup resource");
}
}
示例5: cleanUpOldAttachmentDirectory
import java.io.File; //导入方法依赖的package包/类
private static void cleanUpOldAttachmentDirectory(File attachmentDirOld) {
if (!attachmentDirOld.exists()) {
Timber.d("Old attachment directory doesn't exist: %s", attachmentDirOld.getAbsolutePath());
return;
}
for (File file : attachmentDirOld.listFiles()) {
Timber.d("deleting stale attachment file: %s", file.getName());
if (file.exists() && !file.delete()) {
Timber.d("Failed to delete stale attachement file: %s", file.getAbsolutePath());
}
}
Timber.d("deleting old attachment directory");
if (attachmentDirOld.exists() && !attachmentDirOld.delete()) {
Timber.d("Failed to delete old attachement directory: %s", attachmentDirOld.getAbsolutePath());
}
}
示例6: reset
import java.io.File; //导入方法依赖的package包/类
/**
* Calls {@link #close} if not already closed, and then resets this object back to its initial
* state, for reuse. If data was buffered to a file, it will be deleted.
*
* @throws IOException if an I/O error occurred while deleting the file buffer
*/
public synchronized void reset() throws IOException {
try {
close();
} finally {
if (memory == null) {
memory = new MemoryOutput();
} else {
memory.reset();
}
out = memory;
if (file != null) {
File deleteMe = file;
file = null;
if (!deleteMe.delete()) {
throw new IOException("Could not delete: " + deleteMe);
}
}
}
}
示例7: deleteFile
import java.io.File; //导入方法依赖的package包/类
public static boolean deleteFile(File file) {
if (file.exists() && file.isFile() && file.canWrite()) {
return file.delete();
} else if (file.isDirectory()) {
if (null != file && file.list() != null && file.list().length == 0) {
return file.delete();
} else {
String[] fileList = file.list();
for (String filePaths : fileList) {
File tempFile = new File(file.getAbsolutePath() + "/" + filePaths);
if (tempFile.isFile()) {
tempFile.delete();
} else {
deleteFile(tempFile);
tempFile.delete();
}
}
}
if (file.exists()) {
return file.delete();
}
}
return false;
}
示例8: deleteContents
import java.io.File; //导入方法依赖的package包/类
/**
* Recursively delete everything in {@code dir}.
*/
// TODO: this should specify paths as Strings rather than as Files
public static void deleteContents(File dir) throws IOException {
File[] files = dir.listFiles();
if (files == null) {
throw new IllegalArgumentException("not a directory: " + dir);
}
for (File file : files) {
if (file.isDirectory()) {
deleteContents(file);
}
if (!file.delete()) {
throw new IOException("failed to delete file: " + file);
}
}
}
示例9: cleanCache
import java.io.File; //导入方法依赖的package包/类
public static void cleanCache(Context c) {
File[] list = getCacheDir(c).listFiles(new FilenameFilter(){
@Override
public boolean accept(File dir, String filename) {
return filename.toLowerCase().endsWith(".jpg");
}});
long t = System.currentTimeMillis();
for (File f: list) {
if (f.lastModified() < t - CLEAN_TIME ||
t + CLEAN_TIME < f.lastModified()) {
SendReduced.log("cleaning up "+f);
f.delete();
}
}
}
示例10: prepareDexDir
import java.io.File; //导入方法依赖的package包/类
private static void prepareDexDir(File dexDir, final String extractedFilePrefix) throws IOException {
mkdirChecked(dexDir.getParentFile());
mkdirChecked(dexDir);
File[] files = dexDir.listFiles(new FileFilter() {
public boolean accept(File pathname) {
return !pathname.getName().startsWith(extractedFilePrefix);
}
});
if (files == null) {
Log.w(TAG, "Failed to list secondary dex dir content (" + dexDir.getPath() + ").");
return;
}
for (File oldFile : files) {
Log.i(TAG, "Trying to delete old file " + oldFile.getPath() + " of size " + oldFile.length());
if (oldFile.delete()) {
Log.i(TAG, "Deleted old file " + oldFile.getPath());
} else {
Log.w(TAG, "Failed to delete old file " + oldFile.getPath());
}
}
}
示例11: releaseLock
import java.io.File; //导入方法依赖的package包/类
void releaseLock(final FileLock fileLock, final File lockFile) throws IOException {
if (lockFile == null) {
return;
}
try {
if (fileLock != null) {
fileLock.release();
fileLock.channel().close();
}
} finally {
if (!lockFile.delete()) {
lockFile.deleteOnExit();
}
}
}
示例12: deleteFile
import java.io.File; //导入方法依赖的package包/类
public static boolean deleteFile(File file) {
if (file == null) {
throw new NullPointerException("File can't be null");
}
if (MusicUtils.isFromSdCard(file.getAbsolutePath())) {
DocumentFile documentFile = getDocumentFile(file);
if (documentFile.isDirectory()) {
deleteDirectory(documentFile);
} else {
Logger.log("Deleted File Name " + file.getName());
return documentFile.delete();
}
} else {
return file.delete();
}
return false;
}
示例13: setUp
import java.io.File; //导入方法依赖的package包/类
@Before
public void setUp() throws IOException {
tmpFile = File.createTempFile("locator", ".log");
this.port = portSupplier.getAsInt();
File locatorFile = new File("locator" + this.port + ".dat");
if (locatorFile.exists()) {
locatorFile.delete();
}
}
示例14: deleteDirectory
import java.io.File; //导入方法依赖的package包/类
private void deleteDirectory(File dir) {
if (dir.isDirectory()) {
File[] children = dir.listFiles();
for (int i = 0; i < children.length; i++) {
deleteDirectory(children[i]);
}
}
dir.delete();
}
示例15: testLoggingWithFileAccessException
import java.io.File; //导入方法依赖的package包/类
@SuppressWarnings("boxing")
@Test
public void testLoggingWithFileAccessException() throws Exception {
File log4jFile = createLog4jFile(LOG4J_CONFIG1);
try {
// Set path of log4j properties
log4jFolderPath = log4jFile.getParentFile().getParent();
setSysSetting(log4jFolderPath);
// Invoke "private" method :)
Method method = testElm.getClass().getDeclaredMethod(
"postConstruct");
method.setAccessible(true);
method.invoke(testElm);
// Now we exchange the internal stored file with a mockup :)
File oopsFile = Mockito.mock(File.class);
Field fileField = testElm.getClass().getDeclaredField("logFile");
fileField.setAccessible(true);
fileField.set(testElm, oopsFile);
// And enable damage!
Mockito.when(oopsFile.lastModified()).thenThrow(
new SecurityException());
// Simulate timer (-> this will now result in a security exception!)
testElm.handleTimer(null);
// Simulate timer (-> this will now result in a security exception!)
testElm.handleTimer(null);
} finally {
log4jFile.delete();
resetSysSetting();
}
}