当前位置: 首页>>代码示例>>Java>>正文


Java Context.openFileInput方法代码示例

本文整理汇总了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;
}
 
开发者ID:wkmeijer,项目名称:CS4160-trustchain-android,代码行数:26,代码来源:Util.java

示例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());
    }
}
 
开发者ID:lanceeeaton,项目名称:Text-Rabbit,代码行数:23,代码来源:GameUtils.java

示例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;
    }
}
 
开发者ID:CMPUT301F17T29,项目名称:HabitUp,代码行数:22,代码来源:HabitUpApplication.java

示例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);
        }
    }
}
 
开发者ID:akashdeepsingh9988,项目名称:Cybernet-VPN,代码行数:21,代码来源:ProfileManager.java

示例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;
}
 
开发者ID:subchannel13,项目名称:EnchantedFortress,代码行数:26,代码来源:SaveLoad.java

示例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();
}
 
开发者ID:rainhard,项目名称:wNFCard,代码行数:26,代码来源:CardContent.java

示例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;
}
 
开发者ID:yuhodev,项目名称:login,代码行数:17,代码来源:Index.java

示例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;
    }
}
 
开发者ID:afonsotrepa,项目名称:PocketGopher,代码行数:30,代码来源:History.java

示例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;
}
 
开发者ID:jthomperoo,项目名称:Forge,代码行数:42,代码来源:FileManager.java

示例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 "";
}
 
开发者ID:z-chu,项目名称:FriendBook,代码行数:17,代码来源:FileUtil.java

示例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;
    }
}
 
开发者ID:alexandregpereira,项目名称:goblin-lib,代码行数:8,代码来源:LogFileService.java

示例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;
}
 
开发者ID:MBach,项目名称:home-automation,代码行数:13,代码来源:ImageUtils.java

示例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;
}
 
开发者ID:dmllr,项目名称:IdealMedia,代码行数:12,代码来源:FileUtils.java

示例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; 
}
 
开发者ID:ccfish86,项目名称:sctalk,代码行数:21,代码来源:FileIOTools.java

示例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;
}
 
开发者ID:quaap,项目名称:LaunchTime,代码行数:14,代码来源:SpecialIconStore.java


注:本文中的android.content.Context.openFileInput方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。