hello.
I believe my InputStream is is null. Is there a way to get it to work?

InputStream is=pr.getClass().getResourceAsStream(path);
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package schoolAppView.utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
*
 */
public class PropertyReader {
public String String;
public String path;
public InputStream is;


    public PropertyReader() {

    }

    public void StreamToString(String path) throws IOException {
        this.path= path;
        setpath(path);
        PropertyReader pr = new PropertyReader();
         InputStream is=pr.getClass().getResourceAsStream(path);
        setIs(is);
    }

    public String convertStreamToString() throws IOException {
        this.is=getIs();
        if (is != null) {
            StringBuilder sb = new StringBuilder(0);
            String line;
            try {
                BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
                while ((line = reader.readLine()) != null) {
                    sb.append(line).append("\n");
                }
            } finally {
                is.close();
            }
            return sb.toString();
        } else {
            return "";
        }
    }

    public String getString() {
        return String;
    }

    public void setString(String String) {
        this.String = String;
    }

    public InputStream getIs() {
        return is;
    }

    public void setIs(InputStream is) {
        this.is = is;
    }

    public String getpath() {
        return path;
    }

    public void setpath(String path) {
        this.path = path;
    }


} // End of class
private void readBtnActionPerformed(java.awt.event.ActionEvent evt) {
       String path="/resources/projectnames.properties";
        String line=readTxt.getText();
        PropertyReader pr=new PropertyReader();
        try {
            pr.StreamToString(path);
        } catch (IOException ex) {
            Logger.getLogger(ReadContentTab.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            String ln = pr.convertStreamToString();
        } catch (IOException ex) {
            Logger.getLogger(ReadContentTab.class.getName()).log(Level.SEVERE, null, ex);
        }
        txtArea.setText(ln);
         txtArea.enableInputMethods(true);

    }

Thanks

This article has been dead for over six months. Start a new discussion instead.