本文整理汇总了Java中java.io.File.getAbsoluteFile方法的典型用法代码示例。如果您正苦于以下问题:Java File.getAbsoluteFile方法的具体用法?Java File.getAbsoluteFile怎么用?Java File.getAbsoluteFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.File
的用法示例。
在下文中一共展示了File.getAbsoluteFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: saveInternalState
import java.io.File; //导入方法依赖的package包/类
public IModelState saveInternalState() {
// Create model instance state files, and add them state files to model state
FileBasedModelState algorithmState = new FileBasedModelState();
algorithmState.setDirContainingModelstateFiles(dirForPersistentModelStates);
ArrayList<File> modelInstanceDirs = listModelInstanceDirs();
for (int i = 0; i < modelInstanceDirs.size(); i++) {
File modelInstanceDir = modelInstanceDirs.get(i);
IModelState modelInstanceState = modelInstance_saveInternalState(modelInstanceDir);
File modelStateFile = new File(dirForPersistentModelStates, modelInstanceDir.getName() + zippedModelStateFileExtension);
File fileToBeAddedToState;
if (i == 1) {
// test absolute path
fileToBeAddedToState = modelStateFile.getAbsoluteFile();
} else {
// test relative path
fileToBeAddedToState = modelStateFile;
}
modelInstanceState.savePersistentState(fileToBeAddedToState);
algorithmState.addFile(fileToBeAddedToState);
}
return algorithmState;
}
示例2: getRecordFile
import java.io.File; //导入方法依赖的package包/类
/**
* Get the file to record to for a given remote contact. This will
* implicitly get the current date in file name.
*
* @param remoteContact The remote contact name
* @return The file to store conversation
*/
private File getRecordFile(File dir, String remoteContact, int way) {
if (dir != null) {
// The file name is only to have an unique identifier.
// It should never be used to store datas as may change.
// The app using the recording files should rely on the broadcast
// and on callInfo instead that is reliable.
String datePart = (String) DateFormat.format("yy-MM-dd_kkmmss", new Date());
String remotePart = sanitizeForFile(remoteContact);
String fileName = datePart + "_" + remotePart;
if (way != (SipManager.BITMASK_ALL)) {
fileName += ((way & SipManager.BITMASK_IN) == 0) ? "_out" : "_in";
}
File file = new File(dir.getAbsoluteFile() + File.separator
+ fileName + ".wav");
return file;
}
return null;
}
示例3: contains
import java.io.File; //导入方法依赖的package包/类
public boolean contains(File file) {
File absoluteFile = file.getAbsoluteFile();
String pathWithSeparator = file.getAbsolutePath() + File.separator;
for (File candidateFile : files) {
String candidateFilePathWithSeparator = candidateFile.getPath() + File.separator;
if (pathWithSeparator.startsWith(candidateFilePathWithSeparator)) {
return true;
}
}
for (DirectoryTree tree : trees) {
if (tree.getDir().getAbsoluteFile().equals(absoluteFile) || DirectoryTrees.contains(FileSystems.getDefault(), tree, absoluteFile)) {
return true;
}
}
return false;
}
示例4: getAudioTmpFile
import java.io.File; //导入方法依赖的package包/类
/**
* 获取声音文件的本地地址
*
* @param isTmp 是否是缓存文件, True,每次返回的文件地址是一样的
* @return 录音文件的地址
*/
public static File getAudioTmpFile(boolean isTmp) {
File dir = new File(getCacheDirFile(), "audio");
//noinspection ResultOfMethodCallIgnored
dir.mkdirs();
File[] files = dir.listFiles();
if (files != null && files.length > 0) {
for (File file : files) {
//noinspection ResultOfMethodCallIgnored
file.delete();
}
}
// aar
File path = new File(getCacheDirFile(), isTmp ? "tmp.mp3" : SystemClock.uptimeMillis() + ".mp3");
return path.getAbsoluteFile();
}
示例5: zipFolder
import java.io.File; //导入方法依赖的package包/类
private File zipFolder(File folder, String name) throws IOException {
File zipFile = new File(tempFolder, name + ".zip");
File source = folder.getAbsoluteFile();
Set<String> fileSet = createFileSet(folder, source);
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipFile));
byte[] buffer = new byte[1024];
for (String file : fileSet) {
ZipEntry ze = new ZipEntry(file);
zos.putNextEntry(ze);
FileInputStream fis = new FileInputStream(source + File.separator
+ file);
int len;
while ((len = fis.read(buffer)) > 0) {
zos.write(buffer, 0, len);
}
fis.close();
}
zos.closeEntry();
zos.close();
return zipFile;
}
示例6: createRecursiveFolder
import java.io.File; //导入方法依赖的package包/类
/** Creates new folder and all necessary subfolders
* @param f folder to create
* @return <code>true</code> if the file exists when returning from this method
*/
private static boolean createRecursiveFolder(File f) {
if (f.exists()) {
return true;
}
if (!f.isAbsolute()) {
f = f.getAbsoluteFile();
}
String par = f.getParent();
if (par == null) {
return false;
}
if (!createRecursiveFolder(new File(par))) {
return false;
}
f.mkdir();
return f.exists();
}
示例7: getDexmakerCacheDir
import java.io.File; //导入方法依赖的package包/类
private File getDexmakerCacheDir(){
File cacheDir = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
cacheDir = getApplication().getCodeCacheDir();
} else {
cacheDir = getApplication().getCacheDir();
}
File pandCache = new File(cacheDir.getAbsoluteFile() + "/pand");
if(!pandCache.exists()){
pandCache.mkdir();
}
return pandCache;
}
示例8: loadConfigValues
import java.io.File; //导入方法依赖的package包/类
private ConfigValues loadConfigValues(File file) {
ConfigValues configValues = new ConfigValues();
try {
configValues.setRaw(new String(Files.readAllBytes(file.toPath()), "UTF-8"));
}
catch (IOException e) {
throw new IllegalArgumentException("Could read values file " + file.getAbsoluteFile(), e);
}
return configValues;
}
示例9: writeInfo
import java.io.File; //导入方法依赖的package包/类
/** 寫入資料**/
public void writeInfo(String fileName, String strWrite) {
//WRITE_EXTERNAL_STORAGE
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
WRITE_EXTERNAL_STORAGE_REQUEST_CODE);
}
try {
String fullPath = Environment.getExternalStorageDirectory().getAbsolutePath();
String savePath = fullPath + File.separator + "/" + fileName;
File file = new File(savePath);
if (!file.exists()) {
file.createNewFile();
}
FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
bw.write(strWrite);
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
示例10: getPortraitTmpFile
import java.io.File; //导入方法依赖的package包/类
public static File getPortraitTmpFile() {
// 得到头像目录的缓存地址
File dir = new File(getCacheDirFile(), "portrait");
// 创建所有的对应的文件夹
dir.mkdir();
File[] files = dir.listFiles();
if (files != null && files.length > 0) {
for (File file : files) {
file.delete();
}
}
// 返回一个当前时间的目录文件地址
File path = new File(dir, SystemClock.uptimeMillis()+".jpg");
return path.getAbsoluteFile();
}
示例11: setupTestDirs
import java.io.File; //导入方法依赖的package包/类
@BeforeClass
public static void setupTestDirs() throws IOException {
testDir = new File("target",
TestSharedCacheUploaderService.class.getCanonicalName());
testDir.delete();
testDir.mkdirs();
testDir = testDir.getAbsoluteFile();
}
示例12: getInstance
import java.io.File; //导入方法依赖的package包/类
/**
* 获取缓存实例
* <p>在cacheDir目录</p>
*
* @param cacheDir 缓存目录
* @param maxSize 最大缓存尺寸,单位字节
* @param maxCount 最大缓存个数
* @return {@link CacheUtils}
*/
public static CacheUtils getInstance(@NonNull final File cacheDir, final long maxSize, final int maxCount) {
final String cacheKey = cacheDir.getAbsoluteFile() + "_" + Process.myPid();
CacheUtils cache = CACHE_MAP.get(cacheKey);
if (cache == null) {
cache = new CacheUtils(cacheDir, maxSize, maxCount);
CACHE_MAP.put(cacheKey, cache);
}
return cache;
}
示例13: generateHtmlFile
import java.io.File; //导入方法依赖的package包/类
private static URL generateHtmlFile() {
File file = new File("hello.html");
try (
FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);) {
bw.write("<head></head><body>Hello World!</body>");
return file.toURI().toURL();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例14: getIncomingBuilder
import java.io.File; //导入方法依赖的package包/类
public HierarchicalDirectoryBuilder getIncomingBuilder()
{
File root = new File(path);
if (!root.exists())
{
root.mkdirs();
}
return new HierarchicalDirectoryBuilder(root.getAbsoluteFile(), this.maxFileNo);
}
示例15: save
import java.io.File; //导入方法依赖的package包/类
public void save(File file) throws IOException
{
File parent = file.getParentFile();
if (((parent == null) || parent.exists() || parent.mkdirs()) && (file.exists() || file.createNewFile()))
{
try (FileWriter fileWriter = new FileWriter(file.getAbsoluteFile()))
{
BufferedWriter bw = new BufferedWriter(fileWriter);
bw.write(json());
bw.close();
}
}
}