-1

I am using BufferedReader and BufferedWriter in a progect in order to export it as Jar and use it, My code using the streams is the following

br = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("/data/score.scr")));


bw= new BufferedWriter(new FileWriter("src/data/score.scr"));

I tried to use getClass().getResourceAsStream(); inside BufferedWriter but it doest work, the program works well but it seems ... that the file read is not the one written ... I save a score (BufferedWriter) when I get to the scorepanel (BufferedReader) it is not there

all this in order to export my project as a JAR so I need to modify the second line of my core

FrankelStein
  • 907
  • 2
  • 13
  • 30
  • possible duplicate of [Write To File Method In JAR](http://stackoverflow.com/questions/14403745/write-to-file-method-in-jar) among numerous others; short answer: You can't write to a file in a .jar archive. – Brian Roach Feb 04 '14 at 05:38

2 Answers2

0

In general you cannot write inside a jar file but here is a more detailed answer How can my Java program store files inside of its .jar file?

Community
  • 1
  • 1
clancer
  • 613
  • 4
  • 10
0

You could try using your IDE to do this. eclipse

or through command line

jar cf jar-file input-file(s)

From what it looks like your doing, you don't necessarily need to store data in the jar itself. Just write the data to the same directory or folder as your jar and have your user transfer the entire folder as part of your program.

donkon
  • 909
  • 9
  • 23