當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。