我正在尝试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) 是否可以强制Properties不在前面添加日期评论?我的意思是像这里的第一行:
#Thu May 26 09:43:52 CEST 2011
main=pkg.ClientMain
args=myargs
Run Code Online (Sandbox Code Playgroud)
我想完全摆脱它.我需要我的配置文件是差异相同的,除非有一个有意义的改变.
我有一个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(),然后将它们全部放到一个新对象上.有没有更好的办法?
我想将属性文件存储为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)