android.content.Context#getFileStreamPath ( )源码实例Demo

下面列出了android.content.Context#getFileStreamPath ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: ShellAndroid   文件: NormalReleaser.java
@Override
public File release() throws IOException {
    Context context = getContext();
    int cpuType = Cpu.getCpuType();
    final String cflagName;
    if (cpuType == Cpu.CPU_INTEL){
        cflagName = ShellAndroid.CFLAG_TOOL_X86_FILE_NAME;
    }else{
        cflagName = ShellAndroid.CFLAG_TOOL_FILE_NAME;
    }

    try {
        AssetUtils.extractAsset(context, cflagName, true);
    } catch (IOException e) {
        // e.printStackTrace();
        // extra cflag error, so don't block the sh
        throw e;
    }
    File cFlag = context.getFileStreamPath(cflagName);
    return cFlag;
}
 
源代码2 项目: ShellAndroid   文件: ShellAndroid.java
/**
 * initialize command terminal flag tool
 * with exist cflag
 * @param context
 * @param cFlag a exist cflag
 * @return
 */
public String initFlag(Context context, File cFlag){
    File flagFile = context.getFileStreamPath(FLAG_FILE_NAME + FLAG_ID.incrementAndGet());
    if (!flagFile.exists()) {
        try {
            flagFile.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    if (cFlag != null){
    	mFlagTrigger = cFlag.getAbsolutePath();
    }else{
    	mIsInBlockMode = false;
    }
    mChmod.setChmod(mFlagTrigger, "777");
    return flagFile.getAbsolutePath();
}
 
源代码3 项目: AndroidUSBCamera   文件: TxtOverlay.java
public static void install(Context context) {
    if(instance == null) {
        instance = new TxtOverlay(context.getApplicationContext());

        File youyuan = context.getFileStreamPath("SIMYOU.ttf");
        if (!youyuan.exists()){
            AssetManager am = context.getAssets();
            try {
                InputStream is = am.open("zk/SIMYOU.ttf");
                FileOutputStream os = context.openFileOutput("SIMYOU.ttf", Context.MODE_PRIVATE);
                byte[] buffer = new byte[1024];
                int len = 0;
                while ((len = is.read(buffer)) != -1) {
                    os.write(buffer, 0, len);
                }
                os.close();
                is.close();

            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
 
源代码4 项目: NGA-CLIENT-VER-OPEN-SOURCE   文件: PluginUtils.java
public static void extractPlugin() {
    Context context = ApplicationContextHolder.getContext();
    try {
        String[] fileNames = context.getAssets().list("plugin");
        for (String file : fileNames) {
            File extractFile = context.getFileStreamPath(file);
            try (InputStream is = context.getAssets().open("plugin" + "/" + file);
                 FileOutputStream fos = new FileOutputStream(extractFile)) {
                byte[] buffer = new byte[1024];
                int count;
                while ((count = is.read(buffer)) > 0) {
                    fos.write(buffer, 0, count);
                }
                fos.flush();
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
/** 删除手机内存中的文件*/
public static boolean deleteFile(Context context,String filename){
	File file=context.getFileStreamPath(filename);
	if(!file.exists()){
		return true;
	}else{
		return file.delete();
	}
	
}
 
源代码6 项目: FuzzDroid   文件: Hooker.java
private static void doPrivateDirFileFuzzing(MethodHookParam param, int index, FileFuzzingSerializableObject fuzzyingObject) {
	String fileName = (String)param.args[index];
	Context appContext = Hooker.applicationContext;
	File localFile = appContext.getFileStreamPath(fileName);
	//only create a dummy file if there is no file
	if(!localFile.exists()) {
		//what file format do we need?
		copyCorrectFile(localFile, fuzzyingObject.getFileFormat());			
	}
}
 
源代码7 项目: springreplugin   文件: PackageFilesUtil.java
/**
 * 检查 files 目录下个某个文件是否已经为最新(比 assets 目录下的新)
 *
 * @param c
 * @param filename
 * @return 如果文件比 assets 下的同名文件的时间戳旧,或者文件不存在,则返回 false.
 */
public static boolean isFileUpdated(Context c, String filename) {
    File file = c.getFileStreamPath(filename);
    if (file == null) {
        return false;
    }
    if (!file.exists()) {
        return false;
    }

    long timestampOfFile = getFileTimestamp(c, filename);
    long timestampOfAsset = getBundleTimestamp(c, filename);

    return (timestampOfAsset <= timestampOfFile);
}
 
源代码8 项目: springreplugin   文件: PackageFilesUtil.java
public static boolean isExtractedFromAssetsToFiles(Context c, String filename) {
    File file = c.getFileStreamPath(filename);
    if (file == null || !file.exists()) {
        if (BuildConfig.DEBUG) {
            Log.i(TAG, "Extract no exist file from assets filename = " + filename);
        }
        return true;
    }
    // compare file version for extract
    return compareDataFileVersion(c, filename);
}
 
源代码9 项目: cloudinary_android   文件: FilePayload.java
private File getFile(Context context) throws FileNotFoundException {
    // check if data is an absolute path or a local app path and check if file exists:
    File file = data.contains(File.separator) ? new File(data) : context.getFileStreamPath(data);

    if (!file.exists()) {
        throw new FileNotFoundException(String.format("File '%s' does not exist", data));
    }

    return file;
}
 
源代码10 项目: Varis-Android   文件: FileUtils.java
/**
 * Reads data from the file in internal memory
 *
 * @param fileName File name
 * @param context  Context
 * @return Read data
 */
public static String readInternalFile(String fileName, Context context) {
    String dataFromFile = "";

    File file = context.getFileStreamPath(fileName);
    if (file.exists()) {

        try {
            InputStream inputStream = context.openFileInput(fileName);
            if (inputStream != null) {
                InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
                BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
                String receiveString = "";
                StringBuilder stringBuilder = new StringBuilder();

                while ((receiveString = bufferedReader.readLine()) != null) {
                    stringBuilder.append(receiveString);
                }

                inputStream.close();
                dataFromFile = stringBuilder.toString();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    return dataFromFile;
}
 
源代码11 项目: Cotable   文件: CacheManager.java
/**
 * Juget whether the cache file exists.
 *
 * @param context   context
 * @param cachefile cache file
 * @return true if the cache data exists, false otherwise.
 */
public static boolean isExistDataCache(Context context, String cachefile) {
    if (context == null)
        return false;
    boolean exist = false;
    File data = context.getFileStreamPath(cachefile);
    if (data.exists())
        exist = true;
    return exist;
}
 
源代码12 项目: coloring   文件: ColoringUtils.java
/**
 * Deletes the error log file.
 * @param context
 */
public static void deleteErrorLogFile(Context context) {
    File errorLog = context.getFileStreamPath(context.getString(R.string.error_log_file));
    if (errorLog.exists()) {
        //noinspection ResultOfMethodCallIgnored
        errorLog.delete();
    }
}
 
源代码13 项目: awesomesauce-rfduino   文件: SamsungBleStack.java
/** Function to use our version of BluetoothAdapter and BluetoothDevice if the native Android OS doesn't have 4.3 yet. 
 * @throws IOException 
 * @throws ClassNotFoundException **/
public static void loadSamsungLibraries(Context hostActivityContext) throws IOException, ClassNotFoundException{
	File internalStoragePath = hostActivityContext.getFileStreamPath("com.samsung.ble.sdk-1.0.jar");
	if (!internalStoragePath.exists()){
		
	
	  //We'll copy the SDK to disk so we can open the JAR file:
	  // it has to be first copied from asset resource to a storage location.
	  InputStream jar = hostActivityContext.getAssets().open("com.samsung.ble.sdk-1.0.jar", Context.MODE_PRIVATE);
	  FileOutputStream outputStream = hostActivityContext.openFileOutput("com.samsung.ble.sdk-1.0.jar", Context.MODE_PRIVATE);
	     
	  int size = 0;
	    // Read the entire resource into a local byte buffer.
	    byte[] buffer = new byte[1024];
	    while((size=jar.read(buffer,0,1024))>=0){
	      outputStream.write(buffer,0,size);
	    }
	    jar.close();
	   
	}
	    
	  Log.i(logTag, internalStoragePath.getAbsolutePath()+" exists? "+ internalStoragePath.exists());
	  
         URL[] urls = { new URL("jar:file:" + internalStoragePath.getAbsolutePath()+"!/") };
         URLClassLoader cl  = URLClassLoader.newInstance(urls);
         
         samsungBluetoothAdapterClass = cl.loadClass("android.bluetooth.BluetoothAdapter");
         samsungBluetoothDeviceClass = cl.loadClass("android.bluetooth.BluetoothDevice");
 	
}
 
源代码14 项目: ghwatch   文件: UnreadNotificationsService.java
/**
 * Create service.
 *
 * @param context this service runs in
 */
public UnreadNotificationsService(Context context) {
  this.context = context;
  this.persistFile = context.getFileStreamPath(persistFileName);
  this.authenticationManager = AuthenticationManager.getInstance();
  this.notificationColor = context.getResources().getColor(R.color.apptheme_colorPrimary);
  createNotificationChannel();
}
 
源代码15 项目: Pocket-Plays-for-Twitch   文件: Service.java
public static boolean doesStorageFileExist(String key, Context context) {
    File file = context.getFileStreamPath(key);
    return file.exists();
}
 
源代码16 项目: android-sqrl   文件: identity.java
public boolean deleteIdentityFile(Context con) {
	File file = con.getFileStreamPath("sqrl.dat");
       return file.delete();
}
 
源代码17 项目: ghwatch   文件: AuthenticationManager.java
private File getCuFile(Context context) {
  if (cuFile == null)
    cuFile = context.getFileStreamPath(cuFileName);
  return cuFile;
}
 
源代码18 项目: ghwatch   文件: AuthenticationManager.java
private File getCuliFile(Context context) {
  if (culiFile == null)
    culiFile = context.getFileStreamPath(culiFileName);
  return culiFile;
}
 
源代码19 项目: ExpressHelper   文件: Utility.java
public static String readFile(Context context, String name) throws IOException{
	File file = context.getFileStreamPath(name);
	InputStream is = new FileInputStream(file);

	byte b[] = new byte[(int) file.length()];

	is.read(b);
	is.close();

	String string = new String(b);

	return string;
}
 
源代码20 项目: ghwatch   文件: PreferencesUtils.java
/**
 * Store donation timestamp.
 *
 * @param context
 * @param timestamp to store
 */
public static void storeDonationTimestamp(Context context, Long timestamp) {
  File file = context.getFileStreamPath(DTFN);
  Utils.writeToStore(TAG, context, file, timestamp);
}
 
 方法所在类
 同类方法