Arquivo properties

12 respostas
E

Olá;

Estou precisando fazer leituras em um arquivo Siscom.properties e colocar em um vetor e está dando erro.

import java.util.Properties;
import br.eti.excon.Forms.*;

public class Siscom extends javax.swing.JFrame {
    String[] Inicio = new String[5];
    /** Creates new form Siscom */
    public Siscom() {
        initComponents();
        // Lendo arquivo de configuração de sistema
        Properties inicio = new Properties();
        FileInputStream in = new FileInputStream("Siscom.properties");
        inicio.load(in);
        in.close();
    }
}

erro:

D:\JavaProject\Siscom\src\siscom\br\eti\excon\Forms\Siscom.java:24: cannot find symbol
symbol : class FileInputStream
location: class siscom.br.eti.excon.Forms.Siscom
FileInputStream in = new FileInputStream(“Siscom.properties”);

Valeu.

12 Respostas

rodrigo_gomes

acho q um import java.io.FileInputStream deve resolver :smiley:

E

import java.io.FileInputStream

ou

import java.io.*;

Não funcionou. Continua o mesmo erro.

Valeu.

skill_ufmt

excon:
import java.io.FileInputStream

ou

import java.io.*;

Não funcionou. Continua o mesmo erro.

Valeu.

Seus properties está na mesma pasta da classe?

Fala Rodrigão :slight_smile:

E

Olá;

O Arquivo está na mesma pasta do Siscom.JAR e o erro agora é:

D:\JavaProject\Siscom\src\siscom\br\eti\excon\Forms\Siscom.java:25: unreported exception java.io.FileNotFoundException; must be caught or declared to be thrown
FileInputStream in = new FileInputStream(“Siscom.properties”);

skill_ufmt

excon:
Olá;

O Arquivo está na mesma pasta do Siscom.JAR e o erro agora é:

D:\JavaProject\Siscom\src\siscom\br\eti\excon\Forms\Siscom.java:25: unreported exception java.io.FileNotFoundException; must be caught or declared to be thrown
FileInputStream in = new FileInputStream(“Siscom.properties”);

Tente colocar ele na mesma pasta onde esta esse seu Siscom.java

_fs

excon, você esqueceu de colocar a instrução dentro de um bloco try … catch

try {
    // seu codigo
}
catch( Exception e ) {
   e.printStackTrace();
}

Leia este tutorial:
http://www.guj.com.br/java.artigo.35.1.guj

E

Olá;

Não funcionou. Lí uma materia sobre o assunto e lá dizia que o danado tem que ficar na mesma pasta do .JAR. O que faz sentido pois quando o programa for carregado ele deve acrregar as configurações que está neste arquivo CERTO ?.

Valeu.

skill_ufmt

excon:
Olá;

Não funcionou. Lí uma materia sobre o assunto e lá dizia que o danado tem que ficar na mesma pasta do .JAR. O que faz sentido pois quando o programa for carregado ele deve acrregar as configurações que está neste arquivo CERTO ?.

Valeu.

não era a mesma pasta do .JAVA não?

E

Olá;

Lí um material indicado pelo Lipe sobre o assunto e resolvi mudar a estrutura mas o problema era o try/cath e agora está dando o seguinte erro:

Segue o código

[code]

import java.util.Properties;
import java.io.FileInputStream;
import br.eti.excon.Forms.*;

public class Siscom extends javax.swing.JFrame {
String[] Inicio = new String[5];
/** Creates new form Siscom */
public Siscom() {
initComponents();
// Lendo arquivo de configuração de sistema
File file = new File("Siscom.properties");
Properties inicio = new Properties();
FileInputStream iSiscon = null;
try {
iSiscom = new FileOutputStream(file);
// Lê os dados que estão no arquivo
inicio.load(iSiscom);
iSiscom.close(0);
}
catch (IOException ex) {
System.out.println(ex.getMessage());
ex.printStackTrace();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
private void initComponents() {
toolBar = new javax.swing.JToolBar();
jToggleButton1 = new javax.swing.JToggleButton();
menuLeft = new javax.swing.JPanel();
jButton1 = new javax.swing.JButton();
frmRodape = new javax.swing.JTabbedPane();
frmMensagem = new javax.swing.JDesktopPane();
frmEMail = new javax.swing.JDesktopPane();
frmConteudo = new javax.swing.JPanel();
mainMenu = new javax.swing.JMenuBar();
MCadastro = new javax.swing.JMenu();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("SISCOM - Sistema de gest\u00e3o comercial");
setName("frmSiscom");
toolBar.setBorder(null);
toolBar.setPreferredSize(new java.awt.Dimension(40, 40));
jToggleButton1.setIcon(new javax.swing.ImageIcon("D:\\Projetos\\Icones\\Bitmaps\\Relogio.JPG"));
toolBar.add(jToggleButton1);

getContentPane().add(toolBar, java.awt.BorderLayout.NORTH);

menuLeft.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.CENTER, 5, 1));

menuLeft.setPreferredSize(new java.awt.Dimension(120, 120));
jButton1.setText("jButton1");
jButton1.setAlignmentX(0.5F);
jButton1.setAlignmentY(1.0F);
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

menuLeft.add(jButton1);

getContentPane().add(menuLeft, java.awt.BorderLayout.WEST);

frmRodape.setPreferredSize(new java.awt.Dimension(100, 100));
frmMensagem.setBackground(new java.awt.Color(236, 233, 216));
frmMensagem.setForeground(new java.awt.Color(0, 0, 0));
frmRodape.addTab("Mensagem", frmMensagem);

frmEMail.setBackground(new java.awt.Color(236, 233, 216));
frmRodape.addTab("Correio eletr\u00f4nico", frmEMail);

getContentPane().add(frmRodape, java.awt.BorderLayout.SOUTH);

frmConteudo.setBackground(new java.awt.Color(255, 255, 255));
getContentPane().add(frmConteudo, java.awt.BorderLayout.CENTER);

MCadastro.setText("Cadastro");
mainMenu.add(MCadastro);

setJMenuBar(mainMenu);

java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
setBounds((screenSize.width-705)/2, (screenSize.height-516)/2, 705, 516);
}

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
CadCli frmcadcli = new CadCli();
frmcadcli.setVisible(true);
frmConteudo.add(frmcadcli,java.awt.BorderLayout.CENTER);
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Siscom().setVisible(true);
}
});
}

// Variables declaration - do not modify
private javax.swing.JMenu MCadastro;
private javax.swing.JPanel frmConteudo;
private javax.swing.JDesktopPane frmEMail;
private javax.swing.JDesktopPane frmMensagem;
private javax.swing.JTabbedPane frmRodape;
private javax.swing.JButton jButton1;
private javax.swing.JToggleButton jToggleButton1;
private javax.swing.JMenuBar mainMenu;
private javax.swing.JPanel menuLeft;
private javax.swing.JToolBar toolBar;
// End of variables declaration

}
[code]

erro:

Compiling 1 source file to D:\JavaProject\Siscom\build\classes
D:\JavaProject\Siscom\src\siscom\br\eti\excon\Forms\Siscom.java:48: illegal start of expression

Valeu.

_fs

Pode indicar para gente qual pe a linha 48?

E

Indica nessa linha:

private void initComponents() {

mas a 48 é:

frmMensagem = new javax.swing.JDesktopPane();

e nessas:

private javax.swing.JPanel frmConteudo;

private javax.swing.JDesktopPane frmEMail;

private javax.swing.JDesktopPane frmMensagem;

private javax.swing.JTabbedPane frmRodape;

private javax.swing.JButton jButton1;

private javax.swing.JToggleButton jToggleButton1;

Todas com a mesma msg porém com números de linhas diferentes:

D:\JavaProject\Siscom\src\siscom\br\eti\excon\Forms\Siscom.java:48: illegal start of expression

Valeu.

E

Olá;

Bom pessoal o erro anterior eu encontrei é que eu deletei a chave que fecha o método InitComponents agora o erro é:

Código abaixo estiver fora do método initComponents

File file = new File("Siscom.properties");    
    Properties inicio = new Properties();
    FileInputStream iSiscom = null;
    [b]try {[/b]          
            iSiscom = new FileOutputStream(file);
           // Lê os dados que estão no arquivo
           inicio.load(iSiscom); 
           iSiscom.close(0);
        }
    catch (IOException ex) {
           System.out.println(ex.getMessage());
           ex.printStackTrace();
    }

erro:
D:\JavaProject\Siscom\src\siscom\br\eti\excon\Forms\Siscom.java:27: illegal start of type - Linha do try

D:\JavaProject\Siscom\src\siscom\br\eti\excon\Forms\Siscom.java:149: expected
private javax.swing.JMenu MCadastro;

Código dentro do método initComponents:

[b] File file = new File("Siscom.properties");    [/b]  
    Properties inicio = new Properties();
    FileInputStream iSiscom = null;
    try {
           [b]iSiscom = new FileOutputStream(file);[/b]
           // Lê os dados que estão no arquivo
           inicio.load(iSiscom); 
[b]           iSiscom.close(0);[/b]     
   }
[b]    catch (IOException ex) {[/b]
           System.out.println(ex.getMessage());
           ex.printStackTrace();
    }

erro:

D:\JavaProject\Siscom\src\siscom\br\eti\excon\Forms\Siscom.java:24: cannot find symbol

symbol  : class File

location: class siscom.br.eti.excon.Forms.Siscom

File file = new File(Siscom.properties);

D:\JavaProject\Siscom\src\siscom\br\eti\excon\Forms\Siscom.java:24: cannot find symbol

symbol  : class File

location: class siscom.br.eti.excon.Forms.Siscom

File file = new File(Siscom.properties);

D:\JavaProject\Siscom\src\siscom\br\eti\excon\Forms\Siscom.java:46: cannot find symbol

symbol  : class File

location: class siscom.br.eti.excon.Forms.Siscom

File file = new File(Siscom.properties);

D:\JavaProject\Siscom\src\siscom\br\eti\excon\Forms\Siscom.java:46: cannot find symbol

symbol  : class File

location: class siscom.br.eti.excon.Forms.Siscom

File file = new File(Siscom.properties);

D:\JavaProject\Siscom\src\siscom\br\eti\excon\Forms\Siscom.java:50: cannot find symbol

symbol  : class FileOutputStream

location: class siscom.br.eti.excon.Forms.Siscom

iSiscom = new FileOutputStream(file);

D:\JavaProject\Siscom\src\siscom\br\eti\excon\Forms\Siscom.java:53: cannot find symbol

symbol  : method close(int)

location: class java.io.FileInputStream

iSiscom.close(0);

D:\JavaProject\Siscom\src\siscom\br\eti\excon\Forms\Siscom.java:55: cannot find symbol

symbol  : class IOException

location: class siscom.br.eti.excon.Forms.Siscom

catch (IOException ex) {

que são as linhas em negrito(.

Valeu.

Criado 24 de março de 2005
Ultima resposta 24 de mar. de 2005
Respostas 12
Participantes 4