I'm doing an exercise where it picks and displays three random cards from a file of card images stored in lib/cards/cards of the project. Card images are named from 1.png to 52.png. My java file is in src which has the same level with lib Here's the code I used.
Random rd = new Random();
int[] card = new int[3];
//randomize cards
card[0] = rd.nextInt(52) + 1;
card[1] = rd.nextInt(52) + 1;
card[2] = rd.nextInt(52) + 1;
ImageView image_0 = new ImageView("lib/cards/cards/"+ Integer.toString(card[0]) + ".png");
ImageView image_1 = new ImageView("D:/Visual Studio/New/Test/lib/cards/cards/"+ Integer.toString(card[1]) + ".png");
ImageView image_2 = new ImageView("D:/Visual Studio/New/Test/lib/cards/cards/"+ Integer.toString(card[2]) + ".png");
Absolute path works just fine for image_1 and image_2, and relative path doesn't work for image_0. I wonder if I can use relative path for this, and if I can how to write the correct relative path for this to work.