Java Code Examples for java.io.File.getAbsoluteFile()

The following are Jave code examples for showing how to use getAbsoluteFile() of the java.io.File class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: OpenDA   File: FileBasedModelStateTest.java   View Source Code Vote up 6 votes
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;
		}
 
Example 2
Project: CSipSimple   File: SimpleWavRecorderHandler.java   View Source Code Vote up 6 votes
/**
 * 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;
}
 
Example 3
Project: Reer   File: FileSystemSubset.java   View Source Code Vote up 6 votes
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;
}
 
Example 4
Project: pipe   File: Application.java   View Source Code Vote up 6 votes
/**
 * 获取声音文件的本地地址
 *
 * @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();
}
 
Example 5
Project: KeYExperienceReport   File: ZipUtil.java   View Source Code Vote up 6 votes
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;
}
 
Example 6
Project: incubator-netbeans   File: LocalFileSystem.java   View Source Code Vote up 6 votes
/** 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();
}
 
Example 7
Project: Pand   File: Pand.java   View Source Code Vote up 6 votes
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;
}
 
Example 8
Project: spring-cloud-skipper   File: DefaultPackageReader.java   View Source Code Vote up 5 votes
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;
}
 
Example 9
Project: NFC-UID-Emulator   File: MainActivity.java   View Source Code Vote up 5 votes
/** 寫入資料**/
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();
    }
}
 
Example 10
Project: pipe   File: Application.java   View Source Code Vote up 5 votes
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();
}
 
Example 11
Project: hadoop   File: TestSharedCacheUploaderService.java   View Source Code Vote up 5 votes
@BeforeClass
public static void setupTestDirs() throws IOException {
  testDir = new File("target",
      TestSharedCacheUploaderService.class.getCanonicalName());
  testDir.delete();
  testDir.mkdirs();
  testDir = testDir.getAbsoluteFile();
}
 
Example 12
Project: GitHub   File: CacheUtils.java   View Source Code Vote up 5 votes
/**
 * 获取缓存实例
 * <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;
}
 
Example 13
Project: openjdk-jdk10   File: bug8031109.java   View Source Code Vote up 5 votes
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);
    }
}
 
Example 14
Project: dhus-core   File: HfsManager.java   View Source Code Vote up 5 votes
public HierarchicalDirectoryBuilder getIncomingBuilder()
{
   File root = new File(path);
   if (!root.exists())
   {
      root.mkdirs();
   }
   return new HierarchicalDirectoryBuilder(root.getAbsoluteFile(), this.maxFileNo);
}
 
Example 15
Project: stewie   File: Swagger.java   View Source Code Vote up 5 votes
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();
        }
    }
}
 
Example 16
Project: RLibrary   File: CacheUtils.java   View Source Code Vote up 5 votes
/**
 * 获取缓存实例
 * <p>在cacheDir目录</p>
 *
 * @param cacheDir 缓存目录
 * @param maxSize  最大缓存尺寸,单位字节
 * @param maxCount 最大缓存个数
 * @return {@link CacheUtils}
 */
public static CacheUtils getInstance(@NonNull File cacheDir, long maxSize, int maxCount) {
    final String cacheKey = cacheDir.getAbsoluteFile() + "_" + Process.myPid();
    CacheUtils cache = sCacheMap.get(cacheKey);
    if (cache == null) {
        cache = new CacheUtils(cacheDir, maxSize, maxCount);
        sCacheMap.put(cacheKey, cache);
    }
    return cache;
}
 
Example 17
Project: CodeBroker   File: FileLoad.java   View Source Code Vote up 5 votes
public void init() {
	try {
		configuration = new Configuration();
		File root = new File("");
		File absoluteFile = root.getAbsoluteFile();
		configuration.setDirectoryForTemplateLoading(new File(absoluteFile + "/FreeMakerTemplate"));
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example 18
Project: HeadlineNews   File: CacheUtils.java   View Source Code Vote up 5 votes
/**
 * 获取缓存实例
 * <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;
}
 
Example 19
Project: Hitalk   File: PathUtils.java   View Source Code Vote up 4 votes
public static File getTempPath(File var0) {
  File var1 = new File(var0.getAbsoluteFile() + ".tmp");
  return var1;
}
 
Example 20
Project: openjdk-jdk10   File: Source.java   View Source Code Vote up 2 votes
/**
 * Constructor
 *
 * @param name  source name
 * @param file  file from which source can be loaded
 * @param cs    Charset used to convert bytes to chars
 *
 * @return source instance
 *
 * @throws IOException if source cannot be loaded
 */
public static Source sourceFor(final String name, final File file, final Charset cs) throws IOException {
    final File absFile = file.getAbsoluteFile();
    return sourceFor(name, dirName(absFile, null), new FileData(file, cs));
}