当前位置: 技术问答>java相关
帮忙调试这个程序!!!!谢谢!!!急!
来源: 互联网 发布时间:2017-03-25
本文导语: import java.util.*; import java.io.*; public class ReadIniFile { private static Hashtable has = new Hashtable(); static String head = "#"; public ReadIniFile() { } public void ReadFile() throws Exception { **** ClassLoader cla...
import java.util.*;
import java.io.*;
public class ReadIniFile {
private static Hashtable has = new Hashtable();
static String head = "#";
public ReadIniFile() {
}
public void ReadFile() throws Exception {
**** ClassLoader classloader = getClass().getClassLoader();
**** PropertyResourceBundle resource =new PropertyResourceBundle(classloader.getResourceAsStream("D://ConnectionPool.ini"));
//InputStream resource = getClass().getResourceAsStream("D://ConnectionPool.ini");
Enumeration enu = resource.getKeys();
while (enu.hasMoreElements()) {
String alias = (String) enu.nextElement();
if (alias.endsWith("jdbcDriver")) {
// String str="jdbcDriver";
puthashtable(alias, "jdbcDriver", resource);
}
}
}
private void puthashtable(String alias,String str,PropertyResourceBundle resource)
throws Exception {
//read from resource
String connectalias = alias.substring(0, alias.length() - str.length());
if (has.get(head + connectalias) == null) {
String jdbcDriver = resource.getString(connectalias + "jdbcDriver");
String jdbcURI = resource.getString(connectalias + "jdbcURI");
String dbusername = resource.getString(connectalias + "dbusername");
String dbpassword = resource.getString(connectalias + "dbpassword");
System.out.println(jdbcDriver+""+jdbcURI+""+dbusername+""+dbpassword+"");
}
}
public static void main(String[] args) throws Exception {
ReadIniFile readIniFile1 = new ReadIniFile();
readIniFile1.ReadFile();
}
}
一到*出跳出了
import java.io.*;
public class ReadIniFile {
private static Hashtable has = new Hashtable();
static String head = "#";
public ReadIniFile() {
}
public void ReadFile() throws Exception {
**** ClassLoader classloader = getClass().getClassLoader();
**** PropertyResourceBundle resource =new PropertyResourceBundle(classloader.getResourceAsStream("D://ConnectionPool.ini"));
//InputStream resource = getClass().getResourceAsStream("D://ConnectionPool.ini");
Enumeration enu = resource.getKeys();
while (enu.hasMoreElements()) {
String alias = (String) enu.nextElement();
if (alias.endsWith("jdbcDriver")) {
// String str="jdbcDriver";
puthashtable(alias, "jdbcDriver", resource);
}
}
}
private void puthashtable(String alias,String str,PropertyResourceBundle resource)
throws Exception {
//read from resource
String connectalias = alias.substring(0, alias.length() - str.length());
if (has.get(head + connectalias) == null) {
String jdbcDriver = resource.getString(connectalias + "jdbcDriver");
String jdbcURI = resource.getString(connectalias + "jdbcURI");
String dbusername = resource.getString(connectalias + "dbusername");
String dbpassword = resource.getString(connectalias + "dbpassword");
System.out.println(jdbcDriver+""+jdbcURI+""+dbusername+""+dbpassword+"");
}
}
public static void main(String[] args) throws Exception {
ReadIniFile readIniFile1 = new ReadIniFile();
readIniFile1.ReadFile();
}
}
一到*出跳出了
|
PropertyResourceBundle resource =new PropertyResourceBundle(classloader.getResourceAsStream("D://ConnectionPool.ini"));
是这句的问题拉
你classloader.getResourceAsStream("D://ConnectionPool.ini")返回的是一个为null的InputStream对象,所以会造成空指针错误……
是这句的问题拉
你classloader.getResourceAsStream("D://ConnectionPool.ini")返回的是一个为null的InputStream对象,所以会造成空指针错误……
|
import java.util.*;
import java.io.*;
public class t021216 {
private static Hashtable has = new Hashtable();
static String head = "#";
public t021216() {
}
public void ReadFile() throws Exception {
System.out.println("before");
ClassLoader classloader = getClass().getClassLoader();
System.out.println("after");
PropertyResourceBundle resource =new PropertyResourceBundle(classloader.getResourceAsStream("D:/ConnectionPool.ini"));
//InputStream resource = getClass().getResourceAsStream("D://ConnectionPool.ini");
Enumeration enu = resource.getKeys();
while (enu.hasMoreElements()) {
String alias = (String) enu.nextElement();
if (alias.endsWith("jdbcDriver")) {
// String str="jdbcDriver";
puthashtable(alias, "jdbcDriver", resource);
}
}
}
private void puthashtable(String alias,String str,PropertyResourceBundle resource)
throws Exception {
//read from resource
String connectalias = alias.substring(0, alias.length() - str.length());
if (has.get(head + connectalias) == null) {
String jdbcDriver = resource.getString(connectalias + "jdbcDriver");
String jdbcURI = resource.getString(connectalias + "jdbcURI");
String dbusername = resource.getString(connectalias + "dbusername");
String dbpassword = resource.getString(connectalias + "dbpassword");
System.out.println(jdbcDriver+""+jdbcURI+""+dbusername+""+dbpassword+"");
}
}
public static void main(String[] args) throws Exception {
t021216 readIniFile1 = new t021216();
readIniFile1.ReadFile();
}
import java.io.*;
public class t021216 {
private static Hashtable has = new Hashtable();
static String head = "#";
public t021216() {
}
public void ReadFile() throws Exception {
System.out.println("before");
ClassLoader classloader = getClass().getClassLoader();
System.out.println("after");
PropertyResourceBundle resource =new PropertyResourceBundle(classloader.getResourceAsStream("D:/ConnectionPool.ini"));
//InputStream resource = getClass().getResourceAsStream("D://ConnectionPool.ini");
Enumeration enu = resource.getKeys();
while (enu.hasMoreElements()) {
String alias = (String) enu.nextElement();
if (alias.endsWith("jdbcDriver")) {
// String str="jdbcDriver";
puthashtable(alias, "jdbcDriver", resource);
}
}
}
private void puthashtable(String alias,String str,PropertyResourceBundle resource)
throws Exception {
//read from resource
String connectalias = alias.substring(0, alias.length() - str.length());
if (has.get(head + connectalias) == null) {
String jdbcDriver = resource.getString(connectalias + "jdbcDriver");
String jdbcURI = resource.getString(connectalias + "jdbcURI");
String dbusername = resource.getString(connectalias + "dbusername");
String dbpassword = resource.getString(connectalias + "dbpassword");
System.out.println(jdbcDriver+""+jdbcURI+""+dbusername+""+dbpassword+"");
}
}
public static void main(String[] args) throws Exception {
t021216 readIniFile1 = new t021216();
readIniFile1.ReadFile();
}
|
Parameters:name - the resource name
Returns:an input stream for reading the resource, or null if the resource could not be found
Returns:an input stream for reading the resource, or null if the resource could not be found
|
是不是**** ClassLoader classloader = getClass().getClassLoader();這句話不對.沒有將一個handle指向創建的對象,沒有實例化
|
同意楼上的意见,其实,你可以
ClassLoader classloader = getClass().getClassLoader();
System.out.println("Hello");
PropertyResourceBundle resource =new PropertyResourceBundle(classloader.getResourceAsStream("D://ConnectionPool.ini"));
System.out.println("bye");
然后,就知道,是那句话出现问题了的!
ClassLoader classloader = getClass().getClassLoader();
System.out.println("Hello");
PropertyResourceBundle resource =new PropertyResourceBundle(classloader.getResourceAsStream("D://ConnectionPool.ini"));
System.out.println("bye");
然后,就知道,是那句话出现问题了的!
|
把错误提示,贴出来!