相关疑难解决方法(0)

按新行拆分Java字符串

我正在尝试JTextArea使用正则表达式拆分文本以拆分字符串\n然而,这不起作用,我也试过\r\n|\r|n和许多其他正则表达式的组合.码:

public void insertUpdate(DocumentEvent e) {
    String split[], docStr = null;
    Document textAreaDoc = (Document)e.getDocument();

    try {
        docStr = textAreaDoc.getText(textAreaDoc.getStartPosition().getOffset(), textAreaDoc.getEndPosition().getOffset());
    } catch (BadLocationException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    split = docStr.split("\\n");
}
Run Code Online (Sandbox Code Playgroud)

java regex split newline

372
推荐指数
12
解决办法
48万
查看次数

Properties.store() - 抑制时间戳注释

是否可以强制Properties不在前面添加日期评论?我的意思是像这里的第一行:

#Thu May 26 09:43:52 CEST 2011
main=pkg.ClientMain
args=myargs
Run Code Online (Sandbox Code Playgroud)

我想完全摆脱它.我需要我的配置文件是差异相同的,除非有一个有意义的改变.

java properties

28
推荐指数
3
解决办法
9549
查看次数

如何在java中对属性进行排序?

我有一个Properties变量,有时我需要添加其他属性.

Properties myBasicProps = this.getClass.getResourceAsStream(MY_PROPS_PATH);
...
Properties otherProps = new Properties();
otherProps.load(new StringReader(tempPropsString)); //tempPropsString contains my temporary properties
myBasicProps.putAll(otherProps);
Run Code Online (Sandbox Code Playgroud)

我想myBasicProps在此之后排序.我不想获取所有键和值,对它们进行排序Collections.sort(),然后将它们全部放到一个新对象上.有没有更好的办法?

java sorting properties

21
推荐指数
6
解决办法
2万
查看次数

如何使用排序键将java.util.Properties写入XML?

我想将属性文件存储为XML.有没有办法在执行此操作时对键进行排序,以便生成的XML文件按字母顺序排列?

String propFile = "/path/to/file";
Properties props = new Properties();
/*set some properties here*/
try {
    FileOutputStream xmlStream = new FileOutputStream(propFile);
    /*this comes out unsorted*/
    props.storeToXML(xmlStream,"");
} catch (IOException e) {
    e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)

java xml

13
推荐指数
2
解决办法
2万
查看次数

标签 统计

java ×4

properties ×2

newline ×1

regex ×1

sorting ×1

split ×1

xml ×1