Change FileWriter to OutputStreamWriter?

烈酒焚心 提交于 2019-12-12 01:36:58

问题


How do I convert the FileWriter to OutputStreamWriter? This is the directory that I stored the .java files. src/RX/example.java where RX is the package name. I inserted all the images and text files inside the same directory. Here is my working code with FileWriter.

try {
    StringReader stringReader = new StringReader("Save this Message");

    BufferedReader bufferedReader = new BufferedReader(stringReader);

    FileWriter fileWriter = new FileWriter("src/RX/rxUser.txt");
    BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);

    for(String line = bufferedReader.readLine(); line != null; line =bufferedReader.readLine()) {               
        bufferedWriter.write(line);
        bufferedWriter.newLine();                   
    }
    bufferedReader.close();
    bufferedWriter.close();
} catch (IOException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
}

I actually can go on with this code but in order to work with .jar I have to use the .txt file as a resource. Can someone please alter my code. I am using Netbeans. Thank you.

来源:https://stackoverflow.com/questions/23979791/change-filewriter-to-outputstreamwriter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!