0

我的页面中有不同的链接,例如,

<a href="../test.url">Open</a>

现在当我点击这个链接时,我会得到一个文本模式的 *.url 文件。我发现 URL 文件具有不同的格式,如http://www.cyanwerks.com/file-format-url.html 显示是否有任何简单的方法可以从此文本中获取目标路径?

我知道这只是简单的字符串操作,但是有什么简单的方法可以解析它,可以用于跨平台的 URL 快捷方式文件?

4

1 回答 1

1

As you can see that URL file having same format as .ini file (key/value pair). http://www.cyanwerks.com/file-format-url.html

If you are running your application in Desktop Application then, the files can be manipulated using basic file I\O or the GetPrivateProfileString, GetPrivateProfileSection, WritePrivateProfileSection, WritePrivateProfileSring API functions provided by Windows.

If you want to manually parse it and you having whole file content as one string only then i prefer you to follow below method:

private String getUrl(String fileContent) {
    fileContent = fileContent.trim();
    String[] contentList = fileContent.split("\r\n");
    for (String content : contentList) {
        if (content.toUpperCase().startsWith("URL")) {
            int i = content.indexOf("=");
            return content.substring(i + 1);
        }
    }

}

于 2012-05-08T10:09:47.660 回答