0

I've been trying to create files inside some directories but haven't been able to figure it out.

The point is to create text files inside package dir: com.resources.files but my idea doesn't work.

public boolean archiveFile() {
          //  
        InputStream str = this.getClass().getResourceAsStream("/com/resources/files/"+Filename.txt
        boolean  bol = false;

            file = new File(  str.toString()   );
        if(!file.exists()) {
            try {
                    file.createNewFile();
                    bol = true;
            } catch (Exception e) {
                e.printStackTrace();
            }// try-catch           
        }else {
            bol = false;
        } //  if - else 
            return bol;         
    }//  archiveFile
Caffeinated
  • 11,982
  • 40
  • 122
  • 216
shep
  • 513
  • 2
  • 5
  • 17
  • 1
    new File( str.toString() ); won't work. You have a stream, then you have to read from there. See http://stackoverflow.com/questions/309424/read-convert-an-inputstream-to-a-string – Leo Sep 23 '14 at 23:19
  • what does `getClass().getResourceAsStream` do ? first time to see this – Caffeinated Sep 23 '14 at 23:24

1 Answers1

1

Resources are not files, and resource paths are not directories. Consider the case where a WAR file is being executed without unzipping.

You can't do this.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • ok so can you give me a link o help me understand what the correct procedure is please ? – shep Sep 24 '14 at 05:31