本文整理汇总了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;
}