方便的地方放置更改日志

时间:2011-02-18 14:14:44

标签: java android

我是一名老学校的C程序员,我有把我的更改日志放在主要源文件顶部的注释中的习惯。

我想将更改日志放在一个更方便的位置,以便我可以在运行时将其提取并根据请求显示给用户。

有什么建议吗?

6 个答案:

答案 0 :(得分:2)

大多数项目都会将更改日志保存在项目根目录中名为Changelog的文件中。

这个文件通常是手动创建的:开发人员在提交事物和/或评论(如“简化的全局变量”,“有组织的导入”等)时经常......“创造性”对用户没有多大意义。

在您的情况下,我建议将文件放在显示它的类旁边或(重新)源文件夹的根目录中。这样,您可以使用About.class.getResourceAsStream("Changelog")(相对于About)或getClass().getClassLoader().getResourceAsStream("Changelog")(相对于源根文件夹)轻松加载

答案 1 :(得分:2)

我的建议是将它放在资产下文件系统的html文件中。然后,在要显示更改日志的活动中,只需使用以下Web视图代码:

    WebView changeLogWebView = (WebView) findViewById(R.id.ChangeLogWebView);
    InputStream fin = null;
    try {
        fin = getAssets().open("changelog.html");
        byte[] buffer = new byte[fin.available()];
        fin.read(buffer);
        String contents = new String(buffer, "UTF-8");
        changeLogWebView.loadData(contents, "text/html", "UTF-8");
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        if (fin != null) {
            try {
                fin.close();
            } catch (IOException e) {
            }
        }
    }

答案 2 :(得分:2)

答案 3 :(得分:0)

根据应用程序的结构,您可以设置“关于”菜单选项卡或类似内容,并有一个更改日志按钮,在单击时会显示更改日志。然后,只要进行更改以保持更新,您就可以只读取本地更改日志并复制它。也许是这样的?

答案 4 :(得分:0)

您只需在资源文件夹中添加“raw”文件夹,然后将自己的文件存储在那里 - 也可以是文本文件。文件“res / raw / changelog.txt”在Java代码中获取标识符R.raw.changelog,然后您可以使用getResources().openRawResource()打开并读取该文件。 : - )

http://developer.android.com/reference/android/content/res/Resources.html#openRawResource%28int%29

答案 5 :(得分:0)

这是一段结合了mreichelt和Micah的答案的代码。感谢

WebView中显示的原始资源中的文本。

    WebView computerWebView = (WebView) findViewById(R.id.changelog_webview);
    InputStream istream = null;
    String strLine;
    StringBuilder strbText = new StringBuilder();
    try
        {
        istream = getResources().openRawResource(R.raw.changelog_html);
        InputStreamReader isreader = new InputStreamReader(istream);
        BufferedReader myReader = new BufferedReader(isreader);
        while ((strLine = myReader.readLine()) != null)
            {
            strbText.append(strLine);
            }
        computerWebView.loadData(strbText.toString(), "text/html", "UTF-8");
        }
    catch (Exception e)
        {
        computerWebView
                .loadData("No data to display", "text/html", "UTF-8");
        }
    finally
        {
        if (istream != null)
            try
                {
                istream.close();
                }
            catch (IOException e)
                {
                }
        }