java怎么把String类型的字符串以古文的方式输出?

java怎么把String类型的字符串以古文的方式输出?
2022-03-23 20:03

满意答案

java中将string转换成xml文件,使用开源jar包 dom4j:

package com.webdesk.swing.powertable.util;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter;

public class XmlUtil {

    public static String xmlChangeString(String fileName){
        try {
            SAXReader saxReader = new SAXReader();//新建一个解析类
            Document tempDocument = saxReader.read(XmlUtil.class.getClassLoader().getResourceAsStream(fileName));//读入一个文件
            return tempDocument.asXML();
        } catch (DocumentException e) {
            e.printStackTrace();
        }
        return null;
    }
    //将字符串string类型转换成xml文件
    public static void strChangeXML(String str) throws IOException {
           SAXReader saxReader = new SAXReader();
           Document document;
           try {
            document = saxReader.read(new ByteArrayInputStream(str.getBytes("UTF-8")));
            OutputFormat format = OutputFormat.createPrettyPrint();
            /** 将document中的内容写入文件中 */
            XMLWriter writer = new XMLWriter(new FileWriter(new File("src/com/webdesk/swing/powertable/digester/cctv.xml")),format);
            writer.write(document);
            writer.close();
           } catch (DocumentException e) {
            e.printStackTrace();
           }

   }
}

其他回答

如果上面的命令可以直接在开始运行中执行的话,那么应该使用下面的方式就可以了,你先试试: 

runtime.getruntime().exec("cmd /k java -classpath \"d:\\program files\\weka-3-4\\weka.jar\" weka.classifiers.trees.j48 -p 5 -l \"c:/iris.model\" -t \"d:/iris.arff\" >> a.txt"); 

看这样会出问题吗?如果有问题,详细将你的问题和我说一下。

将上面的a.txt指定一个生成的路径,就可以了,执行程序之后,在c盘根目录下就会生成a.txt文件了:

runtime.getruntime().exec("cmd /k java -classpath \"d:\\program files\\weka-3-4\\weka.jar\" weka.classifiers.trees.j48 -p 5 -l \"c:/iris.model\" -t \"d:/iris.arff\" >> c:\\a.txt");

相关问答

更多

在java中怎么把一个String类型的字符串(去掉,)并循环输出单个的字符串

public class D { public static void main(String[] args) { String uids="1,2,3,4,5,6,7,8,33,44,55,66,"; String a[]; a=uids.split(","); for(int i=0;i<a.length;i++){ System.out.println(a[i]); } } }

java怎么把String类型的字符串以古文的方式输出?

java中将string转换成xml文件,使用开源jar包 dom4j: package com.webdesk.swing.powertable.util; import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileWriter; import java.io.IOException; import org.dom4j.Document; import org.dom4j.DocumentExcept...

String类型字符串替换问题

String[] value = "LastYearEnd(04Report_Data.GF0102_081_D12+04Report_Data.G0101_0910_D10".split("+"); String str = value[0]+value[1];

java 输入字符串 输出升序和降序排序结果

import java.util.Arrays; import java.util.Scanner; public class TestSort { public static void sortTest(){ System.out.println("Please input number, split with ',':"); Scanner in=new Scanner(System.in); String readLine = in.nextLine(); //读取键盘输入的一行(以回车换行...

java,String类型的字符串使用replaceFirst()方法替换指定字符串

java原生替换使用的是正则匹配,效率相对低。 建议使用org.apache.commons.lang.StringUtils.replace,此方法为字符串替换(非正则) http://commons.apache.org/proper/commons-lang/

输出〜字符串(Output ~ string)

来自MSDN : 加号(+),插入符号(^),百分号(%),波浪号(〜)和括号()对SendKeys具有特殊含义。 要指定其中一个字符,请将其括在大括号({})中。 所以,这应该工作: string mystring = "test{~}car"; SendKeys.SendWait(mystring + "{Enter}"); From MSDN: The plus sign (+), caret (^), percent sign (%), tilde (~), and parenthes...

测试通用类型是否为字符串的最佳方式?(Best way to test if a generic type is a string? (C#))

请记住,默认(string)为null,而不是string.Empty。 您可能需要在代码中使用特殊情况: if (typeof(T) == typeof(String)) return (T)(object)String.Empty; Keep in mind that default(string) is null, not string.Empty. You may want a special case in your code: if (typeof(T) == typeof(Stri...

为类型安全扩展字符串 - Java(Extending String for Typesafety - Java)

对于Java 1.5及更高版本,只需使用枚举类型即可 。 对于Java 1.4及更低版本,请使用类型安全枚举模式 。 例如 public class Suit { private final String name; public static final Suit CLUBS =new Suit("clubs"); public static final Suit DIAMONDS =new Suit("diamonds"); public static fin...

Java数据类型:字符串和数组(Java Data Types: String and Array)

在实际层面上, String和char[]之间的主要区别在于前者的实例是不可变的,后者的实例是可变的。 当然,String API提供了各种有用的方法字符串操作方法。 那么让我们来谈谈语言上的相同点和不同点。 首先,(尽管您可能已经听过)Java 中的字符串和数组实例都是对象 。 根据Java语言规范: 4.3.1对象对象是类实例或数组。 引用值(通常只是引用)是指向这些对象的指针,以及一个特殊的空引用,它指的是没有对象。 ...字符串的类是java.lang.String 。 数组和其他对象类型...

相关文章

更多

redis 字符串(String) SET 操作

命令格式: SET key value 把字符串值value存储到key中。如果存在此key,SE ...

java字符串内容的修改?

有字符串&quot;00000000&quot;如何写一段代码将该字符串的任一位修改为1那 问题补充 ...

java字符串解析

源字符串 22:w,22:c,21:r,7:r,7:w,7:c,8:w,8:c,8:d,9:r,9:w ...

遍历字符串每个字符,Stringreader是不是要比string.toCharArray来的快?

我想遍历一个字符串的每一个字符,以前是用string.toCharArray()来转换成一个char[ ...

Java 获取字符串中第N次出现的字符位置

Java 获取字符串中第N次出现的字符位置的背景:截取字符串的时候,大家应该都是str.substri ...

字符串应用之字符串编码转换

无论是对程序的本地化还是国际化,都会涉及到字符编码的转换的问题。尤其在web应用中常常需要处理中文字符 ...

Python 字符串操作

Python 字符串操作,字符串序列用于表示和存储文本,python中字符串是不可变的,一旦声明,不能 ...

mysql截取字符串

mysql截取字符串的函数有left,right,substring,substring_index. ...

shell脚本的字符串截取

以变量 var=http://www.google.com/test.htm为例,讲解shell截取字 ...

最新问答

更多

Python / IPython奇怪的不可重现列表索引超出范围错误(Python/IPython strange non reproducible list index out of range error)

你得到IndexError的原因是你的输入文件显然不是完全用制表符分隔的。 这就是为什么当您尝试访问它时, splits[1]没有任何内容。 您的代码可以使用一些重构。 首先,你正在重复使用if -checks,这是不必要的。 这只是将cds0到7个字符,这可能不是你想要的。 我将以下内容放在一起,以演示如何重构您的代码,使其变得更加pythonic和干燥。 我无法保证它能够与您的数据集一起使用,但我希望它可以帮助您了解如何以不同的方式执行操作。 to_sort = [] # W

故事板从表格单元中延伸出来并显示其详细信息披露按钮(storyboard segue from a tablecell an its Detail Disclosure Button)

我不认为你可以链接一个特定的细节披露按钮瓦特/赛格。 我的故事板是非常程序化的B / C我使用了很多定制CGRect等。 所以我倾向于使用这样的东西: -(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath { [self performSegueWithIdentifier:@"ViewControllerIdentifer"

我们可以将Gherkin功能文件与testcomplete集成(Can we integrate Gherkin feature files with testcomplete)

TestComplete不支持Gherkin功能文件。 但是,TestComplete具有SDK,因此可以自己为此创建扩展。 TestComplete does not support Gherkin feature files. However, TestComplete has SDK so it is possible to create an extension for this by yourself.

TrustAllCertificatesCallback被忽略(TrustAllCertificatesCallback is ignored)

我没有做过这样的事情,但看看我认为可以看出错误的例子。 试试这个代码: static class Program { static void Main() { var tcpclient = new TcpClient("remote.example.com", 443); var tcpstream = tcpclient.GetStream(); var sslstream = new SslStream(tcpstream,

返回嵌套元素的索引(Return index of nested element)

您需要获取父li元素的索引。 否则,您将获得列表项内锚点的索引,该索引始终为零。 $(this.parentNode).index(); You need to get the index of the parent li element. Otherwise you are getting the index of the anchor inside the list item, which will always be zero. $(this.parentNode).index();

在数组中重新编号元素的有效方法(Efficient way of re-numbering elements in an array)

您需要多次迭代列表,我认为没有办法解决这个问题。 毕竟,在开始更改元素(第二遍)之前,首先必须确定不同元素的数量(第一遍)。 但是请注意,由于对index的重复调用而not in列表中具有O(n),因此可能具有最多O(n ^ 2)的不同元素的数量。 或者,您可以使用dict而不是value_map的list 。 字典比列表具有更快的查找速度,因此,复杂性应该确实在O(n)的数量级上。 您可以使用(1)字典理解来确定旧值到新值的映射,以及(2)用于创建更新子项的列表理解。 value_map =

Express app定义的`static`文件夹无法正常工作(Express app defined `static` folder not working properly)

选项1 你可以改变这一行: app.use( express.static(__dirname + '/puplic')); //my public folder. 至 app.use('/oneTime', express.static(__dirname + '/puplic')); //my public folder 选项2 我假设你在公共文件夹中有一个js文件夹,然后你需要更改你的HTML代码:

使用node.js和socket.io每秒广播一次(Using node.js and socket.io to broadcast every second)

对于计时器值,请在服务器端本身每秒更新本地计时器。 每当有任何用户进来时,给他这个值以及计时器的总值。 然后客户端将根据dandavis评论在本地启动自己的计时器,但在服务器端保留一些间隔,如15或10秒,服务器将广播当前计时器值,以便客户端相应地进行同步。 简而言之,服务器将每隔10(n:你决定)秒后广播,但它将在本地每秒更新定时器变量。 每当客户端进入时,它将获得总计时器值和当前计时器值。 广播当前出价的休息功能可以以正常方式完成。 For timer value, keep updatin

如何让XMLSerializer将命名空间添加到嵌套对象中的属性?(How do I get the XMLSerializer to add namespaces to attributes in nested objects?)

IXmlSerializable也许? 注意我还添加了(对A ): [XmlElement("A", Namespace = "http://www.example.com/namespace")] public TestSoapHeaderTypeValuePair A {...} 代码如下: public class TestSoapHeaderTypeValuePair : IXmlSerializable { private string _type; private