本文整理汇总了Java中java.io.File.getPath方法的典型用法代码示例。如果您正苦于以下问题:Java File.getPath方法的具体用法?Java File.getPath怎么用?Java File.getPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.File
的用法示例。
在下文中一共展示了File.getPath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: compressFile
import java.io.File; //导入方法依赖的package包/类
private static void compressFile(String currentDir, ZipOutputStream zout, File[] files) throws Exception {
byte[] buffer = new byte[1024];
for (File fi : files) {
if (fi.isDirectory()) {
compressFile(currentDir + "/" + fi.getName(), zout, fi.listFiles());
continue;
}
ZipEntry ze = new ZipEntry(currentDir + "/" + fi.getName());
FileInputStream fin = new FileInputStream(fi.getPath());
zout.putNextEntry(ze);
int length;
while ((length = fin.read(buffer)) > 0) {
zout.write(buffer, 0, length);
}
zout.closeEntry();
fin.close();
}
}
示例2: prepareDexDir
import java.io.File; //导入方法依赖的package包/类
/**
* This removes any files that do not have the correct prefix.
*/
private static void prepareDexDir(File dexDir, final String extractedFilePrefix)
throws IOException {
dexDir.mkdir();
if (!dexDir.isDirectory()) {
throw new IOException("Failed to create dex directory " + dexDir.getPath());
}
// Clean possible old files
FileFilter filter = new FileFilter() {
@Override
public boolean accept(File pathname) {
return !pathname.getName().startsWith(extractedFilePrefix);
}
};
File[] files = dexDir.listFiles(filter);
if (files == null) {
return;
}
for (File oldFile : files) {
if (!oldFile.delete()) {
} else {
}
}
}
示例3: makeParentDirectories
import java.io.File; //导入方法依赖的package包/类
public void makeParentDirectories(File f) {
String parent = f.getParent();
if (parent != null) {
new File(parent).mkdirs();
} else {
// workaround for jdk 1.1 bug (returns null when there is a parent)
parent = f.getPath();
int index = parent.lastIndexOf('/');
if (index > 0) {
parent = parent.substring(0, index);
new File(parent).mkdirs();
}
}
}
示例4: listClassName
import java.io.File; //导入方法依赖的package包/类
public static ArrayList<String> listClassName(File src) {
if (!src.exists()) return new ArrayList<>();
String[] exts = new String[]{"java"};
Collection<File> files = FileUtils.listFiles(src, exts, true);
ArrayList<String> classes = new ArrayList<>();
String srcPath = src.getPath();
for (File file : files) {
String javaPath = file.getPath();
javaPath = javaPath.substring(srcPath.length() + 1, javaPath.length() - 5); //.java
javaPath = javaPath.replace(File.separator, ".");
classes.add(javaPath);
}
return classes;
}
示例5: FileWordReader
import java.io.File; //导入方法依赖的package包/类
/**
* Creates a new FileWordReader for the given file.
*/
public FileWordReader(File file) throws IOException
{
super(file.getParentFile());
this.name = file.getPath();
this.reader = new LineNumberReader(
new BufferedReader(
new FileReader(file)));
}
示例6: deleteFile
import java.io.File; //导入方法依赖的package包/类
private boolean deleteFile(File file){
ContentResolver cr = context.getContentResolver();
Uri uri = MediaStore.Files.getContentUri("external");
String where = MediaColumns.DATA + "=?";
String[] selectionArgs = { file.getPath() };
boolean ret = cr.delete(uri, where, selectionArgs) > 0;
ret |= file.delete();
return ret;
}
示例7: getSDTotalSize
import java.io.File; //导入方法依赖的package包/类
/**
* 获得SD卡总大小
*
* @return
*/
public static long getSDTotalSize() {
File path = Environment.getExternalStorageDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long totalBlocks = stat.getBlockCount();
return blockSize * totalBlocks;
}
示例8: provideCache
import java.io.File; //导入方法依赖的package包/类
@Provides
@Singleton
public Cache provideCache(@Named("cacheDir") File cacheDir, @Named("cacheSize") long cacheSize) {
Cache cache = null;
try {
cache = new Cache(new File(cacheDir.getPath(), HTTP_CACHE_PATH), cacheSize);
} catch (Exception e) {
e.printStackTrace();
}
return cache;
}
示例9: audiofileIsDown
import java.io.File; //导入方法依赖的package包/类
public static boolean audiofileIsDown(Context context, String url) {
if (TextUtils.isEmpty(url)) {
return false;
}
String fileName = url.substring(url.lastIndexOf("/") + 1);
File mediaStorageDir = new File(
context.getExternalFilesDir(Environment.DIRECTORY_RINGTONES),
AudioFolderName);
if (!mediaStorageDir.exists()) {
return false;
}
String filepath = mediaStorageDir.getPath() + File.separator + fileName;
File file = new File(filepath);
return file.exists();
}
示例10: getAvailableInternalMemorySize
import java.io.File; //导入方法依赖的package包/类
/**
* Get available internal memory size
*
* @return
*/
public static long getAvailableInternalMemorySize() {
File path = Environment.getDataDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long availableBlocks = stat.getAvailableBlocks();
return availableBlocks * blockSize;
}
示例11: playSelectedSong
import java.io.File; //导入方法依赖的package包/类
/**
* Description of the Method
*/
public void playSelectedSong() {
getTheme().unloadSample("file:" + currentSong);
if (selectedItem < itemCount - 1) {
YassScreenGroup group = getGroupAt(getSelectedGroup());
YassSongData sd = getSongDataAt(group.getSongAt(selectedItem));
File f = sd.getAudio();
int startMillis = sd.getPreviewStart();
if (startMillis <= 0) {
startMillis = sd.getMedleyStart();
}
if (startMillis <= 0) {
startMillis = sd.getStart();
}
if (startMillis <= 0) {
startMillis = sd.getGap();
}
if (startMillis <= 0) {
startMillis = 0;
}
currentSong = f.getPath();
if (playbackThread != null) {
playbackThread.interrupt = true;
}
playbackThread = new PlaybackThread(currentSong, startMillis);
playbackThread.start();
}
}
示例12: getAvailableExternalMemorySize
import java.io.File; //导入方法依赖的package包/类
/**
* Get available external memory size
*
* @return
*/
public static long getAvailableExternalMemorySize() {
if (isExternalMemoryAvailable()) {
File path = Environment.getExternalStorageDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long availableBlocks = stat.getAvailableBlocks();
return availableBlocks * blockSize;
} else {
return ERROR;
}
}
示例13: getExecutablePath
import java.io.File; //导入方法依赖的package包/类
private static String getExecutablePath(String path)
throws IOException
{
boolean pathIsQuoted = isQuoted(true, path,
"Executable name has embedded quote, split the arguments");
// Win32 CreateProcess requires path to be normalized
File fileToRun = new File(pathIsQuoted
? path.substring(1, path.length() - 1)
: path);
// From the [CreateProcess] function documentation:
//
// "If the file name does not contain an extension, .exe is appended.
// Therefore, if the file name extension is .com, this parameter
// must include the .com extension. If the file name ends in
// a period (.) with no extension, or if the file name contains a path,
// .exe is not appended."
//
// "If the file name !does not contain a directory path!,
// the system searches for the executable file in the following
// sequence:..."
//
// In practice ANY non-existent path is extended by [.exe] extension
// in the [CreateProcess] funcion with the only exception:
// the path ends by (.)
return fileToRun.getPath();
}
示例14: doTest
import java.io.File; //导入方法依赖的package包/类
/**
* Run the test.
*/
@Override
public void doTest() throws IOException, TestFailedException {
System.out.printf("Xmodem1: basic ASCII file download\n");
// Process:
//
// 1. Extract jermit/tests/data/ALICE26A_NO_EOT.TXT to
// a temp file.
// 2. Spawn 'sx /path/to/ALICE26A_NO_EOT.TXT'
// 3. Spin up XmodemReceiver to download to a temp file.
// 4. Read both files and compare contents.
File source = File.createTempFile("send-xmodem", ".txt");
saveResourceToFile("jermit/tests/data/ALICE26A_NO_EOT.TXT", source);
source.deleteOnExit();
File destination = File.createTempFile("receive-xmodem", ".txt");
destination.deleteOnExit();
ProcessBuilder sxb = new ProcessBuilder("sx", source.getPath());
Process sx = sxb.start();
// Allow overwrite of destination file, because we just created it.
XmodemReceiver rx = new XmodemReceiver(XmodemSession.Flavor.VANILLA,
sx.getInputStream(), sx.getOutputStream(),
destination.getPath(), true);
rx.run();
if (!compareFiles(source, destination)) {
throw new TestFailedException("Files are not the same");
}
}
示例15: getSourcePaths
import java.io.File; //导入方法依赖的package包/类
/**
* get all the dex path
*
* @param context the application context
* @return all the dex path
* @throws PackageManager.NameNotFoundException
* @throws IOException
*/
public static List<String> getSourcePaths(Context context) throws PackageManager.NameNotFoundException, IOException {
ApplicationInfo applicationInfo = context.getPackageManager().getApplicationInfo(context.getPackageName(), 0);
File sourceApk = new File(applicationInfo.sourceDir);
List<String> sourcePaths = new ArrayList<>();
sourcePaths.add(applicationInfo.sourceDir); //add the default apk path
//the prefix of extracted file, ie: test.classes
String extractedFilePrefix = sourceApk.getName() + EXTRACTED_NAME_EXT;
// 如果VM已经支持了MultiDex,就不要去Secondary Folder加载 Classesx.zip了,那里已经么有了
// 通过是否存在sp中的multidex.version是不准确的,因为从低版本升级上来的用户,是包含这个sp配置的
if (!isVMMultidexCapable()) {
//the total dex numbers
int totalDexNumber = getMultiDexPreferences(context).getInt(KEY_DEX_NUMBER, 1);
File dexDir = new File(applicationInfo.dataDir, SECONDARY_FOLDER_NAME);
for (int secondaryNumber = 2; secondaryNumber <= totalDexNumber; secondaryNumber++) {
//for each dex file, ie: test.classes2.zip, test.classes3.zip...
String fileName = extractedFilePrefix + secondaryNumber + EXTRACTED_SUFFIX;
File extractedFile = new File(dexDir, fileName);
if (extractedFile.isFile()) {
sourcePaths.add(extractedFile.getAbsolutePath());
//we ignore the verify zip part
} else {
throw new IOException("Missing extracted secondary dex file '" + extractedFile.getPath() + "'");
}
}
}
if (XModulable.debuggable()) { // Search instant run support only debuggable
sourcePaths.addAll(tryLoadInstantRunDexFile(applicationInfo));
}
return sourcePaths;
}