本文整理了Java中java.io.FileNotFoundException.<init>()
方法的一些代码示例,展示了FileNotFoundException.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileNotFoundException.<init>()
方法的具体详情如下:
包路径:java.io.FileNotFoundException
类名称:FileNotFoundException
方法名:<init>
[英]Constructs a new FileNotFoundException with its stack trace filled in.
[中]构造一个新的FileNotFoundException,并填充其堆栈跟踪。
代码示例来源:origin: dropwizard/dropwizard
@Override
public InputStream open(String path) throws IOException {
final File file = new File(path);
if (!file.exists()) {
throw new FileNotFoundException("File " + file + " not found");
}
return new FileInputStream(file);
}
}
代码示例来源:origin: google/guava
/** Gets URL for base of path containing Finalizer.class. */
URL getBaseUrl() throws IOException {
// Find URL pointing to Finalizer.class file.
String finalizerPath = FINALIZER_CLASS_NAME.replace('.', '/') + ".class";
URL finalizerUrl = getClass().getClassLoader().getResource(finalizerPath);
if (finalizerUrl == null) {
throw new FileNotFoundException(finalizerPath);
}
// Find URL pointing to base of class path.
String urlString = finalizerUrl.toString();
if (!urlString.endsWith(finalizerPath)) {
throw new IOException("Unsupported path style: " + urlString);
}
urlString = urlString.substring(0, urlString.length() - finalizerPath.length());
return new URL(finalizerUrl, urlString);
}
代码示例来源:origin: redisson/redisson
public static void deleteFile(File dest) throws IOException {
if (!dest.exists()) {
throw new FileNotFoundException(MSG_NOT_FOUND + dest);
}
if (!dest.isFile()) {
throw new IOException(MSG_NOT_A_FILE + dest);
}
if (!dest.delete()) {
throw new IOException(MSG_UNABLE_TO_DELETE + dest);
}
}
代码示例来源:origin: apache/geode
protected File processDirOption(final Map<String, Object> options, final String dirValue)
throws FileNotFoundException {
final File inputWorkingDirectory = new File(dirValue);
if (!inputWorkingDirectory.exists()) {
throw new FileNotFoundException(
String.format("The input working directory does not exist: %s",
dirValue));
}
options.put(DIR, inputWorkingDirectory);
return inputWorkingDirectory;
}
代码示例来源:origin: stackoverflow.com
new BufferedInputStream(new FileInputStream(zipFile)));
try {
ZipEntry ze;
byte[] buffer = new byte[8192];
while ((ze = zis.getNextEntry()) != null) {
File file = new File(targetDirectory, ze.getName());
File dir = ze.isDirectory() ? file : file.getParentFile();
if (!dir.isDirectory() && !dir.mkdirs())
throw new FileNotFoundException("Failed to ensure directory: " +
dir.getAbsolutePath());
if (ze.isDirectory())
continue;
代码示例来源:origin: apache/ignite
/**
* @param file File.
* @return Same file.
* @throws FileNotFoundException If does not exist.
*/
private static File checkExists(File file) throws FileNotFoundException {
if (!file.exists())
throw new FileNotFoundException("File " + file.getAbsolutePath() + " does not exist.");
return file;
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Resolve the given resource URI to a {@code java.io.File},
* i.e. to a file in the file system.
* @param resourceUri the resource URI to resolve
* @param description a description of the original resource that
* the URI was created for (for example, a class path location)
* @return a corresponding File object
* @throws FileNotFoundException if the URL cannot be resolved to
* a file in the file system
* @since 2.5
*/
public static File getFile(URI resourceUri, String description) throws FileNotFoundException {
Assert.notNull(resourceUri, "Resource URI must not be null");
if (!URL_PROTOCOL_FILE.equals(resourceUri.getScheme())) {
throw new FileNotFoundException(
description + " cannot be resolved to absolute file path " +
"because it does not reside in the file system: " + resourceUri);
}
return new File(resourceUri.getSchemeSpecificPart());
}
代码示例来源:origin: commons-io/commons-io
throw new NullPointerException("Destination must not be null");
if (!src.exists()) {
throw new FileNotFoundException("Source '" + src + "' does not exist");
if (src.isDirectory()) {
moveDirectoryToDirectory(src, destDir, createDestDir);
} else {
代码示例来源:origin: commons-codec/commons-codec
public XXHash32Test(final String path, final String c) throws IOException {
final URL url = XXHash32Test.class.getClassLoader().getResource(path);
if (url == null) {
throw new FileNotFoundException("couldn't find " + path);
}
URI uri = null;
try {
uri = url.toURI();
} catch (final java.net.URISyntaxException ex) {
throw new IOException(ex);
}
file = new File(uri);
expectedChecksum = c;
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Reverses the migration, in case you want to revert to the older format.
* @param args one parameter, {@code $JENKINS_HOME}
*/
public static void main(String... args) throws Exception {
if (args.length != 1) {
throw new Exception("pass one parameter, $JENKINS_HOME");
}
File root = new File(args[0]);
File jobs = new File(root, "jobs");
if (!jobs.isDirectory()) {
throw new FileNotFoundException("no such $JENKINS_HOME " + root);
}
new RunIdMigrator().unmigrateJobsDir(jobs);
}
private void unmigrateJobsDir(File jobs) throws Exception {
代码示例来源:origin: commons-io/commons-io
/**
* checks requirements for file copy
* @param src the source file
* @param dest the destination
* @throws FileNotFoundException if the destination does not exist
*/
private static void checkFileRequirements(final File src, final File dest) throws FileNotFoundException {
if (src == null) {
throw new NullPointerException("Source must not be null");
}
if (dest == null) {
throw new NullPointerException("Destination must not be null");
}
if (!src.exists()) {
throw new FileNotFoundException("Source '" + src + "' does not exist");
}
}
代码示例来源:origin: nutzam/nutz
/**
* 获取File对象输入流,即使在Jar文件中一样工作良好!! <b>强烈推荐</b>
*
*/
protected static InputStream _input(File file) throws IOException {
if (file.exists())
return new FileInputStream(file);
if (Scans.isInJar(file)) {
NutResource nutResource = Scans.makeJarNutResource(file);
if (nutResource != null)
return nutResource.getInputStream();
}
throw new FileNotFoundException(file.toString());
}
代码示例来源:origin: selenide/selenide
private File firstDownloadedFile(WebElementSource anyClickableElement,
FileDownloadFilter filter, long timeout) throws FileNotFoundException {
List<File> files = filter.getDownloadedFiles();
if (files.isEmpty()) {
throw new FileNotFoundException("Failed to download file " + anyClickableElement +
" in " + timeout + " ms." + filter.getResponses());
}
log.info("Downloaded file: " + files.get(0).getAbsolutePath());
log.info("Just in case, all intercepted responses: " + filter.getResponses());
return files.get(0);
}
}
代码示例来源:origin: stackoverflow.com
void delete(File f) throws IOException {
if (f.isDirectory()) {
for (File c : f.listFiles())
delete(c);
}
if (!f.delete())
throw new FileNotFoundException("Failed to delete file: " + f);
}
代码示例来源:origin: redisson/redisson
private static void checkDirCopy(File srcDir, File destDir) throws IOException {
if (!srcDir.exists()) {
throw new FileNotFoundException(MSG_NOT_FOUND + srcDir);
}
if (!srcDir.isDirectory()) {
throw new IOException(MSG_NOT_A_DIRECTORY + srcDir);
}
if (equals(srcDir, destDir)) {
throw new IOException("Source '" + srcDir + "' and destination '" + destDir + "' are equal");
}
}
代码示例来源:origin: apache/geode
protected static File processDirOption(final Map<String, Object> options, final String dirValue)
throws FileNotFoundException {
final File workingDirectory = new File(dirValue);
if (!workingDirectory.exists()) {
throw new FileNotFoundException(
String.format("The input working directory does not exist: %s",
dirValue));
}
options.put(DIR, workingDirectory);
return workingDirectory;
}
代码示例来源:origin: spotbugs/spotbugs
void f(Object doc, File docFile) throws IOException {
Map<Integer, String> attachments = new HashMap<Integer, String>();
if ((docFile != null) && docFile.exists()) {
attachments.put(doc.hashCode(), doc.toString());
} else {
System.out.println("Can not read uploaded file: " + ((docFile != null) ? docFile.getAbsolutePath() : "") + " : "
+ doc.toString());
throw new FileNotFoundException("file not found in disk!" + ((docFile != null) ? docFile.getAbsolutePath() : "")
+ " : " + doc.toString());
}
}
代码示例来源:origin: redisson/redisson
public static byte[] readBytes(File file, int fixedLength) throws IOException {
if (!file.exists()) {
throw new FileNotFoundException(MSG_NOT_FOUND + file);
}
if (!file.isFile()) {
throw new IOException(MSG_NOT_A_FILE + file);
}
long len = file.length();
if (len >= Integer.MAX_VALUE) {
throw new IOException("File is larger then max array size");
}
if (fixedLength > -1 && fixedLength < len) {
len = fixedLength;
}
byte[] bytes = new byte[(int) len];
RandomAccessFile randomAccessFile = new RandomAccessFile(file, "r");
randomAccessFile.readFully(bytes);
randomAccessFile.close();
return bytes;
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Resolve the given resource URL to a {@code java.io.File},
* i.e. to a file in the file system.
* @param resourceUrl the resource URL to resolve
* @param description a description of the original resource that
* the URL was created for (for example, a class path location)
* @return a corresponding File object
* @throws FileNotFoundException if the URL cannot be resolved to
* a file in the file system
*/
public static File getFile(URL resourceUrl, String description) throws FileNotFoundException {
Assert.notNull(resourceUrl, "Resource URL must not be null");
if (!URL_PROTOCOL_FILE.equals(resourceUrl.getProtocol())) {
throw new FileNotFoundException(
description + " cannot be resolved to absolute file path " +
"because it does not reside in the file system: " + resourceUrl);
}
try {
return new File(toURI(resourceUrl).getSchemeSpecificPart());
}
catch (URISyntaxException ex) {
// Fallback for URLs that are not valid URIs (should hardly ever happen).
return new File(resourceUrl.getFile());
}
}
代码示例来源:origin: apache/geode
@Override
public void load(File dir, SnapshotFormat format) throws IOException, ClassNotFoundException {
if (!dir.exists() || !dir.isDirectory()) {
throw new FileNotFoundException("Unable to load snapshot from " + dir.getCanonicalPath()
+ " as the file does not exist or is not a directory");
}
File[] snapshotFiles = getSnapshotFiles(dir);
load(snapshotFiles, format, createOptions());
}
内容来源于网络,如有侵权,请联系作者删除!