java File handling beginner
06:08 06 Dec 2025

I have a beginner question, when i write a java code for creating or opening a file it doesn't create my file in the current folder where i saved my program instead it will say file not found exception or it will just create a file in the location c://user//{username} folder probably because in this folder my vs-code is installed or folder is created as well.
So what i want is to store my file in the current folder of my program and i want to use relative file path instead of absolute. Is there a solution for it?
This is my code:

import java.util.*;
import java.io.*;
public class Question_3 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        try{
            BufferedWriter bw = new BufferedWriter(new FileWriter("Text_IO.txt"));
            for (int i = 0; i < 100; i++) {
                bw.write((int)(Math.random() * 100) + " ");
            }
            bw.close();
            System.out.println("Successfully wrote 100 random numbers to the file.");

        }
        catch(IOException e){
            System.out.println("An error occurred: " + e.getMessage());
        }
    }
}
java file file-handling