Problemas com uma exceção!

[quote=adriano.ferranti][quote=rodrigo.fai][quote=adriano.ferranti]Você pode tentar usar

public Propertie(String pFile) { String arquivo = Propertie.class.getClassLoader().getResource(pFile).getPath(); getFile(arquivo); } [/quote]

Não deu certo ainda… continua dando NullPointerException soh q agora na linha ond tento corregar o arquivo:

		String arquivo = Propertie.class.getClassLoader().getResource(pFile).getPath();

Deste geito deu arrado ate na minha maquina!
Muito estranho isto! mas qual eh a diferenca d c usar desta maneira??[/quote]

Eita… maldito CTRL+C e CTRL + V

eu quis dizer:

String arquivo = Propertie.class.getClassLoader().getResource(pFile);

sendo que o arquivo deve estar no seu classpath

um exemplo da diferença você pode ver em:

https://lists.xcf.berkeley.edu/lists/advanced-java/2000-October/013378.html

[/quote]

Tb não vai funcionar pq eu tenho q receber uma string! Lembra? Desta maneira ele me retorna uma URL!

Devo trocar o tipo da variavel?

Acho que é mais simples você tentar:

PropertyResourceBundle bundle = null;
bundle = (PropertyResourceBundle) PropertyResourceBundle.getBundle("file_name");
System.out.println(bundle.getString("property_name"));

onde file_name deve ser o nome do pacote onde está o arquivo mais o nome do arquivo sem a extensão.
Ex.: meupacote.meu_arquivo
para o arquivo meu_arquivo.properties dentro do package meupacote

e property_name, óbvio é o nome da propriedade que você quer ler.

[quote=adriano.ferranti]Acho que é mais simples você tentar:

PropertyResourceBundle bundle = null;
bundle = (PropertyResourceBundle) PropertyResourceBundle.getBundle("file_name");
System.out.println(bundle.getString("property_name"));

onde file_name deve ser o nome do pacote onde está o arquivo mais o nome do arquivo sem a extensão.
Ex.: meupacote.meu_arquivo
para o arquivo meu_arquivo.properties dentro do package meupacote

e property_name, óbvio é o nome da propriedade que você quer ler.
[/quote]

ALELUUUUUUIA!!! huahuahuahua

Funcionou agora krinha!!! Vlw msm hein… muito grato!

A classe fikou ate mais enxuta:

package net.sytes.tsda.zeus.properties;

import java.util.PropertyResourceBundle;

public class Propertie
{
	private PropertyResourceBundle bundle = null;
	
	public Propertie(String pFile)
	{
		this.bundle = (PropertyResourceBundle) PropertyResourceBundle.getBundle("/net/sytes/tsda/zeus/properties/"+pFile);
	}
	
	public String getJdbcDriver()
	{
		String jdbcDriver = this.bundle.getString("jdbc.driver");
		
		return jdbcDriver;
	}
	
	public String getBanco(String pBanco)
	{
		String banco = this.bundle.getString(pBanco);
		
		return banco;
	}
	
	public String getUser()
	{
		String user = this.bundle.getString("user");
		
		return user;
	}
	
	public String getPassword()
	{
		String password = this.bundle.getString("password");
		
		return password;
	}
	
	public String getPath()
	{
		String path = this.bundle.getString("diretorio.figuras");
		
		return path;
	}
}

Mas gostaria de saber quao eh a diferença entre a classe Properties e a PropertyResourceBundle!

É isso aí :stuck_out_tongue:

Pode dar uma olhada em:

Valew!!!