本文整理匯總了Java中android.content.Context.openFileInput方法的典型用法代碼示例。如果您正苦於以下問題:Java Context.openFileInput方法的具體用法?Java Context.openFileInput怎麽用?Java Context.openFileInput使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.content.Context
的用法示例。
在下文中一共展示了Context.openFileInput方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: readFile
import android.content.Context; //導入方法依賴的package包/類
/**
* Read a file from storage
* @param context The context.
* @param fileName The file to be read.
* @return The content of the file
*/
public static String readFile(Context context, String fileName) {
try {
StringBuilder text = new StringBuilder();
FileInputStream fis = context.openFileInput(fileName);
BufferedReader br = new BufferedReader(new InputStreamReader(new BufferedInputStream(fis)));
String line;
while ((line = br.readLine()) != null) {
text.append(line);
text.append('\n');
}
br.close();
return text.toString();
}
catch (IOException e) {
e.printStackTrace();
}
return null;
}
示例2: readFromFileFloat
import android.content.Context; //導入方法依賴的package包/類
public static void readFromFileFloat(Context context,ArrayList<Float> list, String fileName)
{
try
{
FileInputStream stream = context.openFileInput(fileName);
InputStreamReader reader = new InputStreamReader(stream);
BufferedReader bufferedReader = new BufferedReader(reader);
String line;
list.clear();
while ((line = bufferedReader.readLine()) != null)
{
list.add(Float.parseFloat(line));
}
}
catch (Exception e)
{
//String tag = GameUtils.class.getSimpleName();
//Log.d(tag, e.toString());
}
}
示例3: loadUserData
import android.content.Context; //導入方法依賴的package包/類
public static boolean loadUserData(Context ctx) {
try {
ArrayList<UserAccount> userList;
FileInputStream fis = ctx.openFileInput(FILENAME);
BufferedReader in = new BufferedReader(new InputStreamReader(fis));
Gson gson = new Gson();
//Taken from https://stackoverflow.com/questions/12384064/gson-convert-from-json-to-a-typed-arraylistt
// 2017-09-19
Type listType = new TypeToken<ArrayList<UserAccount>>(){}.getType();
userList = gson.fromJson(in, listType);
Log.i("debug", "userList is null?"+userList.size());
fileUser = userList.get(0);
Log.i("debug", "user is null?"+getOldUID());
return true;
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
return false;
}
}
示例4: loadVPNList
import android.content.Context; //導入方法依賴的package包/類
private void loadVPNList(Context context) {
profiles = new HashMap<>();
SharedPreferences listpref = context.getSharedPreferences(PREFS_NAME, Activity.MODE_PRIVATE);
Set<String> vlist = listpref.getStringSet("vpnlist", null);
if (vlist == null) {
vlist = new HashSet<>();
}
for (String vpnentry : vlist) {
try {
ObjectInputStream vpnfile = new ObjectInputStream(context.openFileInput(vpnentry + ".vp"));
VpnProfile vp = ((VpnProfile) vpnfile.readObject());
// Sanity check
if (vp == null || vp.mName == null || vp.getUUID() == null) continue;
vp.upgradeProfile();
profiles.put(vp.getUUID().toString(), vp);
} catch (IOException | ClassNotFoundException e) {
VpnStatus.logException("Loading VPN List", e);
}
}
}
示例5: load
import android.content.Context; //導入方法依賴的package包/類
public double[] load(Context context) {
byte[] byteBuffer = new byte[Double.SIZE / Byte.SIZE];
List<Double> data = new ArrayList<>();
Log.i("SaveLoad", "Loading");
try {
FileInputStream stream = context.openFileInput(SaveFileName);
while (stream.read(byteBuffer) == byteBuffer.length && data.size() < MaxSaveLength)
data.add(ByteBuffer.wrap(byteBuffer).getDouble());
stream.close();
Log.i("SaveLoad", "loaded");
upgradeSave(data);
} catch (Exception e) {
Log.e("SaveLoad", "Loading autosave failed", e);
return null;
}
double[] result = new double[data.size()];
for (int i = 0; i < result.length; i++)
result[i] = data.get(i);
return result;
}
示例6: loadCard
import android.content.Context; //導入方法依賴的package包/類
public static int loadCard(Context ctx) {
try {
FileInputStream fis = ctx.openFileInput(SAVE_FILE);
InputStreamReader inputStreamReader = new InputStreamReader(fis);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
String line;
while ((line = bufferedReader.readLine()) != null) {
int idx = line.indexOf('=');
if (idx == -1 || idx != 11)
continue;
String id = line.substring(0, 11);
String name = line.substring(12);
addCard(new CardContent.Card(id, name, ""));
}
bufferedReader.close();
inputStreamReader.close();
fis.close();
} catch (Exception e) {
//e.printStackTrace();
return -1;
}
return ITEM_MAP.size();
}
示例7: loadAllRoutes
import android.content.Context; //導入方法依賴的package包/類
private static String loadAllRoutes(Context context) {
String jsonString;
try {
InputStream is = context.openFileInput("AllRoutes.json");
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
jsonString = new String(buffer, "UTF-8");
} catch (IOException ex) {
ex.printStackTrace();
return null;
}
return jsonString;
}
示例8: read
import android.content.Context; //導入方法依賴的package包/類
/**
* reads the history from a file
*
* @return the visited pages/url's in reverse (latest entry is at index 0)
*/
static public List<String> read(Context context)
{
try
{
FileInputStream inputStream = context.openFileInput(HISTORY_FILE);
BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(inputStream));
//read the page(s) from the file
List<String> visited = new ArrayList<>();
String received;
while ((received = bufferedreader.readLine()) != null)
{
visited.add(0, received);
}
return visited;
}
catch (IOException e)
{
return null;
}
}
示例9: load
import android.content.Context; //導入方法依賴的package包/類
/**
* Gets the stored Forge accounts from the storage
*
* @param context calling context
* @return a hash map of all Forge accounts stored
*/
public static HashMap<UUID, ForgeAccount> load(Context context) {
// Create new hash map
HashMap<UUID, ForgeAccount> accounts = new HashMap<>();
// If storage file exists
if (context.getFileStreamPath(context.getString(R.string.filename_forge_accounts)).exists()) {
// Open file stream
FileInputStream inputStream;
try {
inputStream = context.openFileInput(context.getString(R.string.filename_forge_accounts));
// Open input stream
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
// Place the file contents into a string
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
StringBuilder stringBuilder = new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null) {
stringBuilder.append(line);
}
// Initialise GSON
Gson gson = new Gson();
// Create a list of Forge Accounts from the JSON string
List<ForgeAccount> accountList =
gson.fromJson(stringBuilder.toString(), new TypeToken<List<ForgeAccount>>() {
}.getType());
// Iterate through each Forge account and add it to the hash map
for (ForgeAccount account : accountList) {
accounts.put(account.getId(), account);
}
} catch (Exception e) {
// If there is an error, log it
Log.e(Forge.ERROR_LOG, e.getMessage());
}
}
return accounts;
}
示例10: read
import android.content.Context; //導入方法依賴的package包/類
/**
* 讀取文本文件
*
* @param context
* @param fileName
* @return
*/
public static String read(Context context, String fileName) {
try {
FileInputStream in = context.openFileInput(fileName);
return readInStream(in);
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
示例11: getFileInputStream
import android.content.Context; //導入方法依賴的package包/類
private static FileInputStream getFileInputStream(Context context, String fileName){
try {
return context.openFileInput(fileName);
} catch (FileNotFoundException e) {
return null;
}
}
示例12: loadImage
import android.content.Context; //導入方法依賴的package包/類
public static Bitmap loadImage(Context context, StoryDAO story) {
if (story.getCoverPath() != null) {
try {
FileInputStream fis = context.openFileInput(story.getCoverPath());
return BitmapFactory.decodeStream(fis);
} catch (FileNotFoundException e) {
//Log.d(TAG, "Cover not found!");
e.printStackTrace();
}
}
return null;
}
示例13: read
import android.content.Context; //導入方法依賴的package包/類
public static Object read(String filename, Context context) {
Object t = null;
try {
FileInputStream fis = context.openFileInput(filename);
ObjectInputStream os = new ObjectInputStream(fis);
t = (Object) os.readObject();
os.close();
} catch (Exception e) {
}
return t;
}
示例14: readFile
import android.content.Context; //導入方法依賴的package包/類
/**
* 機身自帶內存
* @param ctx
* @param fileName
* @return
* @throws IOException
*/
public Bitmap readFile(Context ctx, String fileName) throws IOException{
Bitmap image = null;
try {
FileInputStream fis = ctx.openFileInput(fileName);
image = BitmapFactory.decodeStream(fis);
fis.close();
}
catch (IOException e) {
e.printStackTrace();
}
return image;
}
示例15: loadBitmap
import android.content.Context; //導入方法依賴的package包/類
private static Bitmap loadBitmap(Context context, String filename) {
Bitmap bitmap = null;
try {
if (fileExists(context, filename)) {
FileInputStream fis = context.openFileInput(filename);
bitmap = BitmapFactory.decodeStream(fis);
fis.close();
}
} catch (IOException e) {
Log.e("SpecialIconStore", e.getMessage(), e);
}
return bitmap;
}