码迷,mamicode.com
首页 > 其他好文 > 详细

网速计算以及读文件

时间:2015-06-20 09:16:12      阅读:107      评论:0      收藏:0      [点我收藏+]

标签:

public static String formatNetSpeed(long bytes) {
        String result = size + " B/s";
        if (size < 1<<10) {

        } else if (size < 1<<20) {
            result = String.format("%.1f KB/s", size*1.0 / (1<<10));
        } else if (size < 1<<30) {
            result = String.format("%.1f MB/s", size*1.0 / (1<<20));
        } else if (size < 1<<40) {
            result = String.format("%.1f GB/s", size*1.0 / (1<<30));
        }
        if (result.contains(".0")) {
            result = result.replace(".0", "");
        }
        return result;
    }

从配置文件中读取value, 例如keyStr=value时
getValueFromFile(filePath, keyStr, “=”)

    public static String getValueFromFile(String filePath, String key, String seprator) {
        if (TextUtils.isEmpty(filePath) || TextUtils.isEmpty(key)
                || seprator == null) {
            return null;
        }
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new FileReader(new File(filePath)));
            String line = null;
            while ((line = reader.readLine()) != null) {
                if (line.contains(key) && line.contains(seprator)) {
                    return line.substring(line.indexOf(seprator) + seprator.length());
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                reader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return null;
    }

monkey 自动测试
monkey -p com.brian.example –throttle 1000 -s 100 -v -v -v 15000 > /sdcard/monkey_test.txt

网速计算以及读文件

标签:

原文地址:http://blog.csdn.net/brian512/article/details/46565333

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!