All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.arch.util.ConfiguracaoPropriedadesUtils Maven / Gradle / Ivy

package com.arch.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

public class ConfiguracaoPropriedadesUtils {
    private String arquivo;
    private File file;

    public ConfiguracaoPropriedadesUtils(String arquivo) {
        this.arquivo = arquivo;
        file = new File(this.arquivo);

        if (!file.exists()) {
            try {
                file.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public String getArquivo() {
        return this.arquivo;
    }

    public String ler(String nome) {
        String conteudo = "";
        Properties properties = new Properties();
        FileInputStream fis;
        try {
            fis = new FileInputStream(file);
            properties.load(fis);
            conteudo = properties.getProperty(nome);
            fis.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return conteudo;
    }

    public void gravar(String nome, String valor) {
        Properties properties = new Properties();
        FileInputStream fis;
        try {
            fis = new FileInputStream(file);
            properties.load(fis);
            FileOutputStream fos = new FileOutputStream(file);
            properties.setProperty(nome, valor);
            properties.store(fos, "Configura��es do arquivo " + arquivo);
            fis.close();
            fos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy