Settings | Sign in | Sign up

The author has 1 post.

[函數]Android讀取txt文件數據並保存到String變量中

Floor 1 巨大八爪鱼 5/1/15 12:29
public static String readTextFile(String fileName) {
        try {
            FileInputStream in = new FileInputStream(fileName);
            int length = in.available();
            byte[] buffer = new byte[length];
            in.read(buffer);
            in.close();
            String content = EncodingUtils.getString(buffer, "UTF-8");
            return content;
        } catch (FileNotFoundException e) {
            return "";
        } catch (IOException e) {
            return "";
        }
    }

該函數忽略一切錯誤。。。

Content converter:

Reply the post
Content:
User: You are currently anonymous.
Captcha:
Unclear? Try another one.
©2010-2025 Purasbar Ver3.0 [Mobile] [Desktop]
Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported license.