Java 从文本中分析行,重命名

Java 从文本中分析行,重命名,java,regex,string,Java,Regex,String,对于这个庞大的编码世界来说还是相当陌生的,所以请原谅,如果有什么程序可以完成我这段时间需要做的事情的话 这样,我就有了这个字符串: <tbody> <tr> <td id="001" class="rare1">1★ <td><img src="icons/weapons/tdagger/tdagger_001.png" /> <td><a class="fanc

对于这个庞大的编码世界来说还是相当陌生的,所以请原谅,如果有什么程序可以完成我这段时间需要做的事情的话

这样,我就有了这个字符串:

<tbody>
    <tr>
        <td id="001" class="rare1">1★
        <td><img src="icons/weapons/tdagger/tdagger_001.png" />
        <td><a class="fancybox" href="icons_large/weapons/tdagger/tdagger_001.png" rel="tdagger" title="Twin Dagger">
            <img class="large" src="icons_large/weapons_preview/tdagger/tdagger_001.png" /></a>
        <td><a onclick="select_all(this)">ツインダガー</a><br><a href="weapon_04.php#001" title="ツインダガー">Twin Dagger</a>          <td>1<br>S-ATK
        <td><img class="small" src="icons/small/small_01.png" /><br><img class="small" src="icons/small/small_02.png" /><br><img class="small" src="icons/small/small_03.png" />
        <td>59  <br>0   <br>0
        <td>61  <br>0   <br>0
        <td>63  <br>0   <br>0
        <td>66  <br>0   <br>0
        <td>69  <br>0   <br>0
        <td>71  <br>0   <br>0
        <td>74  <br>0   <br>0
        <td>77  <br>0   <br>0
        <td>81  <br>0   <br>0
        <td>84  <br>0   <br>0
        <td>88  <br>0   <br>0
        <td>Common Drop<br>Normal
        <td class="desc">
        <td class="desc">
            <img class="small" src="icons/small/class_04.png" title="Fighter"/>         <td class="desc">
    </tr>

1.★
1
S-ATK

59
0
0 61
0
0 63
0
0 66
0
0 69
0
0 71
0
0 74
0
0 77
0
0 81
0
0 84
0
0 88
0
0 普通下降
正常
把这个乘以90倍,你就会得到我手上的文本文件。如果您对查看txt文件的完整性感兴趣,可以查看此处()

我还有大量与本文相关的图像

我需要做的是获得英文标题(在本例中为)

双匕首

然后重命名匹配的图像文件(我已经下载了)

tdagger_001.png

TwinDeggericon.png

我最初的想法是使用正则表达式获取标题和相关图像文件名,然后将它们写入一个新的文本文件。然后我将使用bluej(java;我熟悉的ide)通过读取文本文件(只有标题和图像名)来重命名文件

我反复浏览我的图像文件列表,如果图像名称等于文本文件中的图像名称,那么我将其名称更改为标题(不带空格),并在末尾添加“Icon.png”


不过坦白地说,我对正则表达式不太熟悉,而且到目前为止,我得到的东西看起来真的不适合我使用。比较名称和重命名文件方面的任何帮助都是一个优点。

据我所知,主要问题是重命名。我猜你想把你的图片保存在和以前一样的目录里,这样你就可以使用它了

Path source = // image source
Files.move(source, source.resolveSibling("newname"));
我希望它对你有用

编辑: 另一个选项是创建
File
类的两个实例以及其中一个的just call renameTo方法,并在括号中传递文件的第二个实例:

// File (or directory) with old name
File file = new File("oldname");

// File (or directory) with new name
File file2 = new File("newname");

if (file2.exists())
   throw new java.io.IOException("file exists");

// Rename file (or directory)
boolean success = file.renameTo(file2);

if (!success) {
   // File was not successfully renamed
}

之后,您可以使用Filewriter将其保存到计算机上

您好,您可以使用DomParser处理标记和属性会更容易