Java 从命令行生成SVG失败,但使用NetBeans成功

Java 从命令行生成SVG失败,但使用NetBeans成功,java,command-line,character-encoding,svg,batik,Java,Command Line,Character Encoding,Svg,Batik,我有一个奇怪的问题。我目前正在尝试svg生成,并使用以下代码生成svg文件: public class SVGGenerator { private static void drawSquare(Graphics2D g2d) { g2d.setPaint(Color.blue); g2d.setFont(new Font(g2d.getFont().getName(), g2d.getFont().getStyle(), 60)); g

我有一个奇怪的问题。我目前正在尝试svg生成,并使用以下代码生成svg文件:

public class SVGGenerator {

    private static void drawSquare(Graphics2D g2d) {
        g2d.setPaint(Color.blue);
        g2d.setFont(new Font(g2d.getFont().getName(), g2d.getFont().getStyle(), 60));
        g2d.drawString("Ruccc", 200, 64);
        g2d.setFont(new Font(g2d.getFont().getName(), g2d.getFont().getStyle(), 120));
        AffineTransform fontAT = new AffineTransform();

        // get the current font
        Font theFont = g2d.getFont();

        // Derive a new font using a rotatation transform
        fontAT.rotate(Math.PI / 2);
        Font theDerivedFont = theFont.deriveFont(fontAT);

        // set the derived font in the Graphics2D context
        g2d.setFont(theDerivedFont);

        // Render a string using the derived font
        g2d.setPaint(Color.red);
        g2d.drawString("bloody", 200, 64);
        g2d.setPaint(Color.green);
        // put the original font back
        g2d.setFont(new Font(g2d.getFont().getName(), g2d.getFont().getStyle(), 60));
        g2d.drawString("Ruccc", 200, 440);
    }

    public static void GenerateSVG()
    {
        DOMImplementation dom = GenericDOMImplementation.getDOMImplementation();
        Document doc = dom.createDocument(null, "svg", null);
        SVGGraphics2D generator = new SVGGraphics2D(doc);
        drawSquare(generator);
        // Write the generated SVG document to a file
        try {
                FileWriter file = new FileWriter("c://Development//out.svg");
                PrintWriter writer = new PrintWriter(file);
                generator.stream(writer);
                writer.close();
            } catch (IOException ioe) {
                System.err.println("IO problem: " + ioe.toString());
            }
    }    
}
如果我使用NetBeans运行我的程序,它将生成以下内容:

<?xml version="1.0"?>
<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.0//EN'
          'http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd'>
<svg fill-opacity="1" xmlns:xlink="http://www.w3.org/1999/xlink" color-rendering="auto" color-interpolation="auto" stroke="black" text-rendering="auto" stroke-linecap="square" stroke-miterlimit="10" stroke-opacity="1" shape-rendering="auto" fill="black" stroke-dasharray="none" font-weight="normal" stroke-width="1" xmlns="http://www.w3.org/2000/svg" font-family="&apos;Dialog&apos;" font-style="normal" stroke-linejoin="miter" font-size="12" stroke-dashoffset="0" image-rendering="auto"
><!--Generated by the Batik Graphics2D SVG Generator--><defs id="genericDefs"
  /><g
  ><g fill="blue" font-size="60" stroke="blue"
    ><text x="200" xml:space="preserve" y="64" stroke="none"
      >Rúccc</text
      ><text x="200" font-size="120" y="64" transform="matrix(0,1,-1,0,264,-136)" fill="red" stroke="none" xml:space="preserve"
      >bloody</text
    ></g
    ><g fill="lime" font-size="60" stroke="lime"
    ><text x="200" xml:space="preserve" y="440" stroke="none"
      >Rúccc</text
    ></g
  ></g
></svg
>

但是,如果不是Rúccc I type Ruccc,而是从命令行和浏览器都可以。我想问题在于匈牙利人的性格。如何使用Java中的svg生成处理匈牙利字符,以便从命令行正确生成svg?感谢您的输入。

似乎是字符编码问题。从命令行开始使用
-Dfile.encoding=…
(用所需的编码替换点)

使用的2参数形式并指定允许匈牙利语输出的适当字符集

<?xml version="1.0"?>
<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.0//EN'
          'http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd'>
<svg fill-opacity="1" xmlns:xlink="http://www.w3.org/1999/xlink" color-rendering="auto" color-interpolation="auto" stroke="black" text-rendering="auto" stroke-linecap="square" stroke-miterlimit="10" stroke-opacity="1" shape-rendering="auto" fill="black" stroke-dasharray="none" font-weight="normal" stroke-width="1" xmlns="http://www.w3.org/2000/svg" font-family="&apos;Dialog&apos;" font-style="normal" stroke-linejoin="miter" font-size="12" stroke-dashoffset="0" image-rendering="auto"
><!--Generated by the Batik Graphics2D SVG Generator--><defs id="genericDefs"
  /><g
  ><g fill="blue" font-size="60" stroke="blue"
    ><text x="200" xml:space="preserve" y="64" stroke="none"
      >Rúccc</text
      ><text x="200" font-size="120" y="64" transform="matrix(0,1,-1,0,264,-136)" fill="red" stroke="none" xml:space="preserve"
      >bloody</text
    ></g
    ><g fill="lime" font-size="60" stroke="lime"
    ><text x="200" xml:space="preserve" y="440" stroke="none"
      >Rúccc</text
    ></g
  ></g
></svg
>
XML5617: Illegal XML character. 
out.svg, line 9 character 9