Opening a file | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 1

Opening a file

So I'm making a program that opens a file that needs to be processed once opened. I've already opened the file on my code. Here is what I've done so far: import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; { public static void main(String[] args) { try { File myObj = new File("random.txt"); Scanner myReader = new Scanner(myObj); while (myReader.hasNextLine()) { String info = myReader.nextLine(); System.out.println(info + " "); } myReader.close(); } catch (FileNotFoundException e) { System.out.println("Something's gone wrong"); e.printStackTrace(); } } } However, it needs to to do the following as well: - get the original file name (with or without path) from the user. - specify the output file name (with or without path). - allow the user to set the field width and set the precision (after decimal point). - allow the user to set how many columns on each line (must be from 1 to 5) The new file should not be created until: - the input file already exists - the destination file does not exist - the field width is specified - the precision is specified, and - the number of columns is in the range of 1 to 5 I'm struggling heavily on that assignment. Can someone help me on that please?

15th Feb 2023, 5:40 AM
Gradi Maxime Kasita Mbatika
1 Resposta
0
Also, the ā€œrandom.txtā€ is the file that Iā€™m processing. It is a file full of floating numbers. If you guys want to, I can post it.
15th Feb 2023, 7:20 PM
Gradi Maxime Kasita Mbatika