Hello and thanks in advance for your time.
Why is the InputStream not excepting the String path to a package containing a properties file?
private void writeBtnActionPerformed(java.awt.event.ActionEvent evt) {
String path="/view/resources/projectnames.properties";
String txtIn=writeTxt.getText();
PropertyWriter pw = new PropertyWriter();
try {
pw.StreamToString(path, txtIn);
} catch (IOException ex) {
Logger.getLogger(WriteContentTab.class.getName()).log(Level.SEVERE, null, ex);
}
try {
String txtOut = pw.convertStreamToString();
} catch (IOException ex) {
Logger.getLogger(WriteContentTab.class.getName()).log(Level.SEVERE, null, ex);
}
txtArea.enableInputMethods(true);
txtArea.setText(txtOut);
}
package view.utils;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
/**
*
*/
public class PropertyWriter {
public String line;
public String path;
public InputStream is;
public PropertyWriter() {
}
public void StreamToString(String path,String line) throws IOException {
this.line=line;
setLine(line);
this.path= path;
setPath(path);
System.out.println("absolutePath: "+getPath());
PropertyWriter pw = new PropertyWriter();
InputStream is=pw.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 getLine() {
return line;
}
public void setLine(String line) {
this.line = line;
}
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
run:
in main: String: keycards.xml
doc=null
start obj() type= tools
absolutePath: /view/resources/projectnames.properties
txt param: The text to be sent to txt area