BuildXMLAntCompile标记在上下文中产生错误,该上下文包含用于编码utf-8的不可Map字符

cs7cruho  于 2021-06-29  发布在  Java
关注(0)|答案(0)|浏览(146)

我想将一个windows文本文件(fromtextfile)转换为另一个windows文本文件(totextfile)。
在fromtext文件中,我查找一个char并对该行进行一些测试。然后我写下修改过的totext文件。
我要找的字符,已经直接从fromtextfile复制到我的程序源代码的字符串常量中,因为它似乎是windows特定的字符。
在我的eclipse中,这和预期的一样有效。
但是当我尝试用ant构建它时,我从ant编译器得到了一些错误:

StripTextFile.java:29: error: unmappable character for encoding UTF-8
[javac]     private static String S1 = "?";
[javac]                                 ^
[javac] StripTextFile.java:30: error: unmappable character for encoding UTF-8
[javac]     private static String S2 = "?";
[javac]                                 ^

Build.xml:
<target name="compile" depends="clean, makedir" description="compiles the Stuff">
    <echo message="compile" />
    <javac executable="${javaCompiler}" encoding="UTF-8" debug="true" includeantruntime="false" destdir="${classes.dir}" classpathref="classpath">
        <src path="${sources.dir}" />
    </javac>
</target>

我怎样才能解决这个问题?
环境:面向java开发人员的eclipse ide(包括孵化组件)版本:2020-06(4.16.0)构建id:20200615-1200
java:jdk1.8.0旸

Part of the FromTextFile.txt (copied from the Browser, Disqus Comment System):
        2
        •
        Teilen ›
        Avatar
        2
        •
        Teilen ›
        Avatar

sscce公司:

import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import de.mke.util.FileUtil;

public class StripTextFile {

    public static void main(String[] args) throws IOException {

        if (args.length == 1) {
            String fileName = args[0];
            if (FileUtil.existFile(fileName)) {
                new StripTextFile().readTextFile(fileName);
            } else {
                System.out.println("File <" + fileName + "> not found!");
            }
        } else {
            System.out.println("Inputparameter not correct!");
        }
    }

    private static String S1 = "›";
    private static String S2 = "•";

    public void readTextFile(String textInputFileName) throws IOException {
        boolean skipNextLine = false;
        List<String> outputList = Collections.checkedList(new ArrayList<>(), String.class);
        List<String> inputList = Collections.checkedList(
                new ArrayList<>(Files.readAllLines(Paths.get(textInputFileName), Charset.forName("UTF-8"))),
                String.class);

        for (String entry : inputList) {
            System.out.println(entry);
            if (!skipNextLine) {
                if (entry.isEmpty()) {
                } else if (entry.contains("Teilen " + S1)) {
                } else if (entry.contains(S2 + " vor")) {
                    outputList.add(entry.toUpperCase());
                    skipNextLine = true;
                } else if (entry.endsWith("Avatar")) {
                    outputList.add("");
                } else if (entry.endsWith(S2)) {
                } else if (entry.endsWith("1")) {
                } else {
                    outputList.add(entry);
                }
            } else {
                skipNextLine = false;
            }
        }
        Files.write(Paths.get(addUnderscoreToFilename(textInputFileName)), outputList, Charset.forName("UTF-8"));
    }

    public static String addUnderscoreToFilename(final String input) {
        int i = input.lastIndexOf(".");
        String name = input.substring(0, i);
        String extension = input.substring(i + 1);
        return name + "_" + "." + extension;
    }
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题