com.crashnote.core.util.FileUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of crashnote-servlet Show documentation
Show all versions of crashnote-servlet Show documentation
Reports exceptions from Java servlet apps to crashnote.com
/**
* Copyright (C) 2011 - 101loops.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.crashnote.core.util;
import com.crashnote.core.model.data.DataObject;
import java.io.*;
import java.util.Date;
/**
* Utility class to execute basic file system operations like reading and writing
*/
public class FileUtil {
// INTERFACE ==================================================================================
public File getOrCreate(final File f) {
if (!f.exists()) f.mkdirs();
return f;
}
public static File getTmpFolder() {
return new File(getTmpFolderPath());
}
public static String getTmpFolderPath() {
return makeFolderPath(System.getProperty("java.io.tmpdir"));
}
private static String makeFolderPath(final String path) {
if (!(path.endsWith("/") || path.endsWith("\\")))
return path + System.getProperty("file.separator");
else
return path;
}
/**
* Return a list of absolute file paths inside a directory -
* the result can be null if file is not a directory!
*/
public String[] listFiles(final File dir) {
return dir.list();
}
public int countFiles(final File dir) {
final String[] files = listFiles(dir);
return (files != null) ? files.length : 0;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy