-1

I have created a file named Student, however I would like to create a folder called School and make a file called Student inside that folder how can I do it?

My code below:

public void upload() throws IOException {
        FileWriter writer = new FileWriter("student.txt");
        BufferedWriter buffer = new BufferedWriter(writer);
        buffer.write(generatedText);
        buffer.close();
    }
Flav
  • 188
  • 2
  • 15

1 Answers1

0

You can use mkdir() method from File class:

new File("path\\School").mkdir();
FileWriter writer = new FileWriter("path\\School\\student.txt");
BufferedWriter buffer = new BufferedWriter(writer);
buffer.write("Hello");
buffer.close();

Here path need to be replaced with your system path for the .

Gaurav Jeswani
  • 4,410
  • 6
  • 26
  • 47