android.content.Context.getFileStreamPath()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(8.2k)|赞(0)|评价(0)|浏览(291)

本文整理了Java中android.content.Context.getFileStreamPath()方法的一些代码示例,展示了Context.getFileStreamPath()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Context.getFileStreamPath()方法的具体详情如下:
包路径:android.content.Context
类名称:Context
方法名:getFileStreamPath

Context.getFileStreamPath介绍

暂无

代码示例

代码示例来源:origin: oasisfeng/condom

@Override public File getFileStreamPath(String name) {
  return mBase.getFileStreamPath(name);
}

代码示例来源:origin: stackoverflow.com

public boolean fileExists(Context context, String filename) {    
  File file = context.getFileStreamPath(filename);
  if(file == null || !file.exists()) {
    return false;
  }
  return true;
}

代码示例来源:origin: ankidroid/Anki-Android

/**
 * If you want to make sure that the next exception of any time is posted, you need to clear limiter data
 *
 * ACRA 5.3.x does this automatically on version upgrade (https://github.com/ACRA/acra/pull/696), until then they blessed deleting file
 * @param context the context leading to the directory with ACRA limiter data
 */
public static void deleteACRALimiterData(Context context) {
  context.getFileStreamPath("ACRA-limiter.json").delete();
}

代码示例来源:origin: AltBeacon/android-beacon-library

protected void updateMonitoringStatusTime(long time) {
  File file = mContext.getFileStreamPath(STATUS_PRESERVATION_FILE_NAME);
  file.setLastModified(time);
}

代码示例来源:origin: AltBeacon/android-beacon-library

protected long getLastMonitoringStatusUpdateTime() {
  File file = mContext.getFileStreamPath(STATUS_PRESERVATION_FILE_NAME);
  return file.lastModified();
}

代码示例来源:origin: android-hacker/VirtualXposed

public static void startup(Context context) {
  File flagFile = context.getFileStreamPath(Constants.NO_NOTIFICATION_FLAG);
  if (Build.VERSION.SDK_INT >= 25 && flagFile.exists()) {
    showNotification = false;
  }
  context.startService(new Intent(context, DaemonService.class));
  if (VirtualCore.get().isServerProcess()) {
    // PrivilegeAppOptimizer.notifyBootFinish();
    DaemonJobService.scheduleJob(context);
  }
}

代码示例来源:origin: facebook/stetho

private void handlePipeOutput(OutputStream output) throws DumpException {
 File hprofFile = mContext.getFileStreamPath("hprof-dump.hprof");
 try {
  writeHprof(hprofFile);
  try {
   InputStream input = new FileInputStream(hprofFile);
   try {
    Util.copy(input, output, new byte[2048]);
   } finally {
    input.close();
   }
  } catch (IOException e) {
   throw new DumpException("Failure copying " + hprofFile + " to dumper output");
  }
 } finally {
  if (hprofFile.exists()) {
   hprofFile.delete();
  }
 }
}

代码示例来源:origin: ACRA/acra

public void store(@NonNull Context context) throws IOException {
  IOUtils.writeStringToFile(context.getFileStreamPath(FILE_LIMITER_DATA), toJSON());
}

代码示例来源:origin: facebook/facebook-android-sdk

private static void saveEventsToDisk(
    PersistedEvents eventsToPersist) {
  ObjectOutputStream oos = null;
  Context context = FacebookSdk.getApplicationContext();
  try {
    oos = new ObjectOutputStream(
        new BufferedOutputStream(
            context.openFileOutput(PERSISTED_EVENTS_FILENAME, 0)));
    oos.writeObject(eventsToPersist);
  } catch (Exception e) {
    Log.w(TAG, "Got unexpected exception while persisting events: ", e);
    try {
      context.getFileStreamPath(PERSISTED_EVENTS_FILENAME).delete();
    } catch (Exception innerException) {
      // ignore
    }
  } finally {
    Utility.closeQuietly(oos);
  }
}

代码示例来源:origin: facebook/stetho

@Override
public void dump(DumperContext dumpContext) throws DumpException {
 final PrintStream output = dumpContext.getStdout();
 Iterator<String> argsIter = dumpContext.getArgsAsList().iterator();
 String outputPath = argsIter.hasNext() ? argsIter.next() : null;
 if (outputPath == null) {
  usage(output);
 } else {
  if ("-".equals(outputPath)) {
   handlePipeOutput(output);
  } else {
   File outputFile = new File(outputPath);
   if (!outputFile.isAbsolute()) {
    outputFile = mContext.getFileStreamPath(outputPath);
   }
   writeHprof(outputFile);
   output.println("Wrote to " + outputFile);
  }
 }
}

代码示例来源:origin: tiann/understand-plugin-framework

/**
 * 把Assets里面得文件复制到 /data/data/files 目录下
 *
 * @param context
 * @param sourceName
 */
public static void extractAssets(Context context, String sourceName) {
  AssetManager am = context.getAssets();
  InputStream is = null;
  FileOutputStream fos = null;
  try {
    is = am.open(sourceName);
    File extractFile = context.getFileStreamPath(sourceName);
    fos = new FileOutputStream(extractFile);
    byte[] buffer = new byte[1024];
    int count = 0;
    while ((count = is.read(buffer)) > 0) {
      fos.write(buffer, 0, count);
    }
    fos.flush();
  } catch (IOException e) {
    e.printStackTrace();
  } finally {
    closeSilently(is);
    closeSilently(fos);
  }
}

代码示例来源:origin: tiann/understand-plugin-framework

/**
 * 把Assets里面得文件复制到 /data/data/files 目录下
 *
 * @param context
 * @param sourceName
 */
public static void extractAssets(Context context, String sourceName) {
  AssetManager am = context.getAssets();
  InputStream is = null;
  FileOutputStream fos = null;
  try {
    is = am.open(sourceName);
    File extractFile = context.getFileStreamPath(sourceName);
    fos = new FileOutputStream(extractFile);
    byte[] buffer = new byte[1024];
    int count = 0;
    while ((count = is.read(buffer)) > 0) {
      fos.write(buffer, 0, count);
    }
    fos.flush();
  } catch (IOException e) {
    e.printStackTrace();
  } finally {
    closeSilently(is);
    closeSilently(fos);
  }
}

代码示例来源:origin: tiann/understand-plugin-framework

private static File getPluginBaseDir(String packageName) {
  if (sBaseDir == null) {
    sBaseDir = UPFApplication.getContext().getFileStreamPath("plugin");
    enforceDirExists(sBaseDir);
  }
  return enforceDirExists(new File(sBaseDir, packageName));
}

代码示例来源:origin: facebook/facebook-android-sdk

context.getFileStreamPath(PERSISTED_EVENTS_FILENAME).delete();
} catch (Exception ex) {
  Log.w(TAG, "Got unexpected exception when removing events file: ", ex);

代码示例来源:origin: android-hacker/VirtualXposed

public static VPackage parsePackage(File packageFile) throws Throwable {
  PackageParser parser = PackageParserCompat.createParser(packageFile);
  PackageParser.Package p = PackageParserCompat.parsePackage(parser, packageFile, 0);
  if (p.requestedPermissions.contains("android.permission.FAKE_PACKAGE_SIGNATURE")
      && p.mAppMetaData != null
      && p.mAppMetaData.containsKey("fake-signature")) {
    String sig = p.mAppMetaData.getString("fake-signature");
    p.mSignatures = new Signature[]{new Signature(sig)};
    VLog.d(TAG, "Using fake-signature feature on : " + p.packageName);
  } else {
    try {
      PackageParserCompat.collectCertificates(parser, p, PackageParser.PARSE_IS_SYSTEM);
    } catch (Throwable e) {
      VLog.e(TAG, "collectCertificates failed", e);
      if (VirtualCore.get().getContext().getFileStreamPath(Constants.FAKE_SIGNATURE_FLAG).exists()) {
        VLog.w(TAG, "Using fake signature: " + p.packageName);
        p.mSignatures = new Signature[]{new Signature(FAKE_SIG)};
      } else {
        throw e;
      }
    }
  }
  return buildPackageCache(p);
}

代码示例来源:origin: Trumeet/MiPushFramework

@Override public File getFileStreamPath(String name) {
  return mBase.getFileStreamPath(name);
}

代码示例来源:origin: android-hacker/VirtualXposed

boolean enableXposed = !VirtualCore.get().getContext().getFileStreamPath(".disable_xposed").exists();
if (enableXposed) {
  VLog.i(TAG, "Xposed is enabled.");

代码示例来源:origin: julian-klode/dns66

/**
 * Write to the given file in the private files dir, first renaming an old one to .bak
 *
 * @param context  A context
 * @param filename A filename as for @{link {@link Context#openFileOutput(String, int)}}
 * @return See @{link {@link Context#openFileOutput(String, int)}}
 * @throws IOException See @{link {@link Context#openFileOutput(String, int)}}
 */
public static OutputStream openWrite(Context context, String filename) throws IOException {
  File out = context.getFileStreamPath(filename);
  // Create backup
  out.renameTo(context.getFileStreamPath(filename + ".bak"));
  return context.openFileOutput(filename, Context.MODE_PRIVATE);
}

代码示例来源:origin: julian-klode/dns66

@Test
public void testOpenWrite() throws Exception {
  File file = mock(File.class);
  File file2 = mock(File.class);
  FileOutputStream fos = mock(FileOutputStream.class);
  when(mockContext.getFileStreamPath(eq("filename"))).thenReturn(file);
  when(mockContext.getFileStreamPath(eq("filename.bak"))).thenReturn(file2);
  when(mockContext.openFileOutput(eq("filename"), anyInt())).thenReturn(fos);
  assertSame(fos, FileHelper.openWrite(mockContext, "filename"));
  Mockito.verify(file).renameTo(file2);
  Mockito.verify(mockContext).openFileOutput(eq("filename"), anyInt());
}

代码示例来源:origin: stackoverflow.com

// Renames a file stored in the application's private store.
public static void RenameAppFile(Context context, String originalFileName, String newFileName) {
  File originalFile = context.getFileStreamPath(originalFileName);
  File newFile = new File(originalFile.getParent(), newFileName);
  if (newFile.exists()) {
    // Or you could throw here.
    context.deleteFile(newFileName);        
  }
  originalFile.renameTo(newFile);
}

相关文章

Context类方法