本文整理汇总了Java中java.io.FileNotFoundException类的典型用法代码示例。如果您正苦于以下问题:Java FileNotFoundException类的具体用法?Java FileNotFoundException怎么用?Java FileNotFoundException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FileNotFoundException类属于java.io包,在下文中一共展示了FileNotFoundException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getJarFile
import java.io.FileNotFoundException; //导入依赖的package包/类
private JarFile getJarFile(URL url) throws IOException {
// Optimize case where url refers to a local jar file
if (isOptimizable(url)) {
//HACK
//FileURLMapper p = new FileURLMapper (url);
File p = new File(url.getPath());
if (!p.exists()) {
throw new FileNotFoundException(p.getPath());
}
return new JarFile (p.getPath());
}
URLConnection uc = getBaseURL().openConnection();
uc.setRequestProperty(USER_AGENT_JAVA_VERSION, JAVA_VERSION);
return ((JarURLConnection)uc).getJarFile();
}
示例2: getDiskStoreIdFromInitFile
import java.io.FileNotFoundException; //导入依赖的package包/类
private String getDiskStoreIdFromInitFile(File dir, String fileName)
throws FileNotFoundException, IOException {
FileInputStream fis = new FileInputStream(new File(dir, fileName));
try {
byte[] bytes = new byte[1 + 8 + 8];
fis.read(bytes);
ByteBuffer buffer = ByteBuffer.wrap(bytes);
// Skip the record type.
buffer.get();
long least = buffer.getLong();
long most = buffer.getLong();
UUID id = new UUID(most, least);
return id.toString();
} finally {
fis.close();
}
}
示例3: renameDocument
import java.io.FileNotFoundException; //导入依赖的package包/类
@Override
public String renameDocument(String documentId, String displayName) throws FileNotFoundException {
// Since this provider treats renames as generating a completely new
// docId, we're okay with letting the MIME type change.
displayName = FileUtils.buildValidFatFilename(displayName);
final RootFile before = getRootFileForDocId(documentId);
final RootFile after = new RootFile(before.getParent(), displayName);
if(!RootCommands.renameRootTarget(before, after)){
throw new IllegalStateException("Failed to rename " + before);
}
final String afterDocId = getDocIdForRootFile(new RootFile(after.getParent(), displayName));
if (!TextUtils.equals(documentId, afterDocId)) {
notifyDocumentsChanged(documentId);
return afterDocId;
} else {
return null;
}
}
示例4: deleteUnnecessaryFakeDirectories
import java.io.FileNotFoundException; //导入依赖的package包/类
private void deleteUnnecessaryFakeDirectories(Path f) throws IOException {
while (true) {
try {
String key = pathToKey(f);
if (key.isEmpty()) {
break;
}
S3AFileStatus status = getFileStatus(f);
if (status.isDirectory() && status.isEmptyDirectory()) {
if (LOG.isDebugEnabled()) {
LOG.debug("Deleting fake directory " + key + "/");
}
s3.deleteObject(bucket, key + "/");
statistics.incrementWriteOps(1);
}
} catch (FileNotFoundException | AmazonServiceException e) {
}
if (f.isRoot()) {
break;
}
f = f.getParent();
}
}
示例5: execution
import java.io.FileNotFoundException; //导入依赖的package包/类
@Override
protected TOExecutionResult execution(File transformedAppFolder, TransformationContext transformationContext) {
File fileToBeModified = getAbsoluteFile(transformedAppFolder, transformationContext);
if (!fileToBeModified.exists()) {
// TODO Should this be done as pre-validation?
FileNotFoundException ex = new FileNotFoundException("File to be modified has not been found");
return TOExecutionResult.error(this, ex);
}
TOExecutionResult result = null;
try {
FileUtils.fileAppend(fileToBeModified.getAbsolutePath(), EolHelper.findEolDefaultToOs(fileToBeModified));
FileUtils.fileAppend(fileToBeModified.getAbsolutePath(), newLine);
String details = "A new line has been added to file " + getRelativePath(transformedAppFolder, fileToBeModified);
result = TOExecutionResult.success(this, details);
} catch (IOException e) {
result = TOExecutionResult.error(this, e);
}
return result;
}
示例6: createDoc
import java.io.FileNotFoundException; //导入依赖的package包/类
public void createDoc() throws FileNotFoundException{
/** 创建Document对象(word文档) */
Rectangle rectPageSize = new Rectangle(PageSize.A4);
rectPageSize = rectPageSize.rotate();
// 创建word文档,并设置纸张的大小
doc = new Document(PageSize.A4);
file=new File(path+docFileName);
fileOutputStream=new FileOutputStream(file);
/** 建立一个书写器与document对象关联,通过书写器可以将文档写入到输出流中 */
RtfWriter2.getInstance(doc, fileOutputStream );
doc.open();
//设置页边距,上、下25.4毫米,即为72f,左、右31.8毫米,即为90f
doc.setMargins(90f, 90f, 72f, 72f);
//设置标题字体样式,粗体、二号、华文中宋
tfont = DocStyleUtils.setFontStyle("华文中宋", 22f, Font.BOLD);
//设置正文内容的字体样式,常规、三号、仿宋_GB2312
bfont = DocStyleUtils.setFontStyle("仿宋_GB2312", 16f, Font.NORMAL);
}
示例7: loadConfig
import java.io.FileNotFoundException; //导入依赖的package包/类
/**
* Attempts to load properties file with database configuration. Must
* include username, password, database, and hostname.
*
* @param configPath path to database properties file
* @return database properties
* @throws IOException if unable to properly parse properties file
* @throws FileNotFoundException if properties file not found
*/
private Properties loadConfig(String configPath) throws FileNotFoundException, IOException {
// Specify which keys must be in properties file
Set<String> required = new HashSet<>();
required.add("username");
required.add("password");
required.add("database");
required.add("hostname");
// Load properties file
Properties config = new Properties();
config.load(new FileReader(configPath));
// Check that required keys are present
if (!config.keySet().containsAll(required)) {
String error = "Must provide the following in properties file: ";
throw new InvalidPropertiesFormatException(error + required);
}
return config;
}
示例8: save
import java.io.FileNotFoundException; //导入依赖的package包/类
/**
* Save the cached profiles to disk
*/
public void save()
{
String s = this.gson.toJson((Object)this.getEntriesWithLimit(1000));
BufferedWriter bufferedwriter = null;
try
{
bufferedwriter = Files.newWriter(this.usercacheFile, Charsets.UTF_8);
bufferedwriter.write(s);
return;
}
catch (FileNotFoundException var8)
{
;
}
catch (IOException var9)
{
return;
}
finally
{
IOUtils.closeQuietly((Writer)bufferedwriter);
}
}
示例9: testInventoryModule
import java.io.FileNotFoundException; //导入依赖的package包/类
@Test
public void testInventoryModule() throws FileNotFoundException {
Path modulesFolder = Paths.get("src/test/resources/generic");
Path modulePath = modulesFolder.resolve("example_module.json");
JsonReader reader = new JsonReader(new FileReader(modulePath.toString()));
JsonObject module = new JsonParser().parse(reader).getAsJsonObject();
// example_module has 4 codes:
// Examplitis condition
// Examplitol medication
// Examplotomy_Encounter
// Examplotomy procedure
Concepts.inventoryModule(concepts, module);
assertEquals(4, concepts.cellSet().size());
assertEquals("Examplitis", concepts.get("SNOMED-CT", "123"));
assertEquals("Examplitol", concepts.get("RxNorm", "456"));
assertEquals("Examplotomy Encounter", concepts.get("SNOMED-CT", "ABC"));
assertEquals("Examplotomy", concepts.get("SNOMED-CT", "789"));
}
示例10: openLog
import java.io.FileNotFoundException; //导入依赖的package包/类
void openLog(final String loggingFolder) {
try {
filename = loggingFolder + "/ProcessingTime_" + filterClassName
+ DATE_FORMAT.format(new Date()) + ".txt";
logStream = new PrintStream(new BufferedOutputStream(
new FileOutputStream(new File(filename))));
log.log(Level.INFO, "Created motion flow logging file with "
+ "processing time statistics at {0}", filename);
logStream.println("Processing time statistics of motion flow "
+ "calculation, averaged over event packets.");
logStream.println("Date: " + new Date());
logStream.println("Filter used: " + filterClassName);
logStream.println();
logStream.println("timestamp [us] | processing time [us]");
} catch (FileNotFoundException ex) {
log.log(Level.SEVERE, null, ex);
}
}
示例11: addNewConfigResource
import java.io.FileNotFoundException; //导入依赖的package包/类
private void addNewConfigResource(String rsrcName, String keyGroup,
String groups, String keyHosts, String hosts)
throws FileNotFoundException, UnsupportedEncodingException {
// location for temp resource should be in CLASSPATH
Configuration conf = new Configuration();
URL url = conf.getResource("hdfs-site.xml");
String urlPath = URLDecoder.decode(url.getPath().toString(), "UTF-8");
Path p = new Path(urlPath);
Path dir = p.getParent();
tempResource = dir.toString() + "/" + rsrcName;
String newResource =
"<configuration>"+
"<property><name>" + keyGroup + "</name><value>"+groups+"</value></property>" +
"<property><name>" + keyHosts + "</name><value>"+hosts+"</value></property>" +
"</configuration>";
PrintWriter writer = new PrintWriter(new FileOutputStream(tempResource));
writer.println(newResource);
writer.close();
Configuration.addDefaultResource(rsrcName);
}
示例12: indexDocs
import java.io.FileNotFoundException; //导入依赖的package包/类
public static void indexDocs(IndexWriter writer, File file)
throws IOException {
// do not try to index files that cannot be read
if (file.canRead()) {
if (file.isDirectory()) {
String[] files = file.list();
// an IO error could occur
if (files != null) {
for (int i = 0; i < files.length; i++) {
indexDocs(writer, new File(file, files[i]));
}
}
} else {
System.out.println("adding " + file);
try {
writer.addDocument(FileDocument.Document(file));
}
// at least on windows, some temporary files raise this exception with an "access denied" message
// checking if the file can be read doesn't help
catch (FileNotFoundException fnfe) {
;
}
}
}
}
示例13: InsertPerfInfoIntoFiles
import java.io.FileNotFoundException; //导入依赖的package包/类
static void InsertPerfInfoIntoFiles(String basePath, String cardName, String experimentID, HashMap<Short, Pair<Short, Long>> perfResultsSubpartsRaw) throws FileNotFoundException, IOException {
File dir = new File(basePath);
String[] filesArray = dir.list();
if ((filesArray != null) && (dir.isDirectory() == true)) {
// make subdir for results
String outputDir = String.format("%s\\perf\\%s\\", basePath, experimentID);
new File(outputDir).mkdirs();
for (String fileName : filesArray) {
File dir2 = new File(basePath + fileName);
if (!dir2.isDirectory()) {
InsertPerfInfoIntoFile(String.format("%s\\%s", basePath, fileName), cardName, experimentID, outputDir, perfResultsSubpartsRaw);
}
}
}
}
示例14: downloadRawUserFile
import java.io.FileNotFoundException; //导入依赖的package包/类
@Override
public byte[] downloadRawUserFile(final String userId, final String fileName) {
final Result<byte[]> result = new Result<byte[]>();
try {
runJobWithRetries(new JobRetryHelper() {
@Override
public void run(Objectify datastore) {
UserFileData ufd = datastore.find(userFileKey(userKey(userId), fileName));
if (ufd != null) {
result.t = ufd.content;
} else {
throw CrashReport.createAndLogError(LOG, null, collectUserErrorInfo(userId, fileName),
new FileNotFoundException(fileName));
}
}
}, true);
} catch (ObjectifyException e) {
throw CrashReport.createAndLogError(LOG, null, collectUserErrorInfo(userId, fileName), e);
}
return result.t;
}
示例15: init
import java.io.FileNotFoundException; //导入依赖的package包/类
public void init() throws Exception, CertificateException, FileNotFoundException, IOException {
if(sipStack.securityManagerProvider.getKeyManagers(false) == null ||
sipStack.securityManagerProvider.getTrustManagers(false) == null ||
sipStack.securityManagerProvider.getTrustManagers(true) == null) {
if (logger.isLoggingEnabled(LogWriter.TRACE_DEBUG)) {
logger.logDebug("TLS initialization failed due to NULL security config");
}
return; // The settings
}
sslServerCtx = SSLContext.getInstance("TLS");
sslServerCtx.init(sipStack.securityManagerProvider.getKeyManagers(false),
sipStack.securityManagerProvider.getTrustManagers(false),
null);
sslClientCtx = SSLContext.getInstance("TLS");
sslClientCtx.init(sipStack.securityManagerProvider.getKeyManagers(true),
sipStack.securityManagerProvider.getTrustManagers(true),
null);
}