本文整理匯總了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);
}