我想把JComBox中的要显示的文件,从poperties文件中读取出来显示?也就是如何读取propeties文件呢? 谁能给个小例子啊?谢谢;==================比如有三行字符串1,初中2.高中3.大学我想把这个字符串放在文件中,动态读取,然后每条放入jComBox中,方便以后修改,该如何读取呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Properties properties = new Properties(); properties.load(new FileInputStream(new File("C:\\x.properties"))); properties.get("1") properties.get("2") ......x.properties文件内容:1=xxx12=xxx23=xxx3 楼上这个扩展性不太好吧?如果哪天我在properties文件中增加了选项,岂不是还要修改程序,,,如果增加一些扩展性,在文件中增加条目,程序不用修改呢? Acylas(Acylas)我用你的方法获取出来的中文有乱码啊 假设你的文件结构如下初中高中大学 JComboBox comboBox =new JComboBox(); try{File aFile=new File("fileName.properties"); FileReader filereader=new FileReader(sendmanFile); BufferedReader in=new BufferedReader(filereader); while(true){ String line=in.readLine(); if(line!=null){ comboBox.addItem(line); } else break; } }那么将创建你需要的JComboBox,可以在你的properties文件增加任意行 既然是配置文件,就应该张得搞笑一点嘛:写个的XML的配置文件不是蛮好: public Document createDOMDocument(File file) { Document document; DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); try { DocumentBuilder documentBuilder = null; synchronized (documentBuilderFactory) { documentBuilder = documentBuilderFactory.newDocumentBuilder(); } document = documentBuilder.parse(file); } catch (Exception e) { throw e; } return document; } public static Node selectSingleNode(Node node, String xpath) throws Exception { Node nodeResult; try { nodeResult = selectSingleNode(node, xpath, node); } catch (Exception e) { throw e; } return nodeResult; } public String getNodeAttribute(Node node, String attributeName) { NamedNodeMap map = node.getAttributes(); Node nodeAttribute = map.getNamedItem(attributeName); if (nodeAttribute == null) { return null; } else { return (nodeAttribute.getNodeValue()); } } 爽不爽?我没测过O 关于正则表达式的问题 JAVA 四则运算 代码 大家都来想想,用最简单的方法做 java面试经常遇到的sqltimian java连接数据库的时候那3个.jar得文件是从哪里考到哪里来得?谢谢大家 简单的问题,快来抢分! 如何实现文件夹的解压缩? 我需要解压在Unix下经过compress的文件,谁有相关的java资源,谢谢。 十万火急,一定加分!!! 请问HTML中嵌入JAVA APPLET的具体格式是什么? =========问题很严重========= 问题很简单。。。
properties.load(new FileInputStream(new File("C:\\x.properties")));
properties.get("1")
properties.get("2")
......x.properties文件内容:
1=xxx1
2=xxx2
3=xxx3
修改程序,,,如果增加一些扩展性,在文件中增加条目,程序不用修改呢?
初中
高中
大学
JComboBox comboBox =new JComboBox();
try{File aFile=new File("fileName.properties");
FileReader filereader=new FileReader(sendmanFile);
BufferedReader in=new BufferedReader(filereader);
while(true){
String line=in.readLine();
if(line!=null){
comboBox.addItem(line);
}
else break;
} }那么将创建你需要的JComboBox,可以在你的properties文件增加任意行
Document document; DocumentBuilderFactory documentBuilderFactory
= DocumentBuilderFactory.newInstance(); try
{
DocumentBuilder documentBuilder = null;
synchronized (documentBuilderFactory)
{
documentBuilder = documentBuilderFactory.newDocumentBuilder();
}
document = documentBuilder.parse(file);
} catch (Exception e)
{
throw e;
}
return document;
}
public static Node selectSingleNode(Node node, String xpath)
throws Exception
{
Node nodeResult;
try
{
nodeResult = selectSingleNode(node, xpath, node);
} catch (Exception e)
{
throw e;
}
return nodeResult;
}
public String getNodeAttribute(Node node, String attributeName)
{ NamedNodeMap map = node.getAttributes();
Node nodeAttribute = map.getNamedItem(attributeName);
if (nodeAttribute == null)
{
return null;
} else
{
return (nodeAttribute.getNodeValue());
}
} 爽不爽?我没测过O