I am new to Java programming I am preparing an assignment and I need some help with my code, say instructions I need to manage exceptions in my I wrote the general exception because I do not know what to do. Any suggestion will really be helpful. Also, I am posting only to the class where I have to keep blocks blocking my efforts. thank you in advanced. Here's my code: Your method throws and throws the following exceptions: So its up-to-date and what exceptions you want to handle numberOfRows () and
convertFileArray () methods. This exercise requires reading from a CSV file, in a multidimensional array of files Converts, prints the array on the screen. My program works fine, the only issue I have is that I did not know which exceptions I can handle in those 2 ways.
import java.io. *; Import java.nio.file. *; Import java.util.StringTokenizer; Public Class ReadFiles {int rows = 0; Int column = 0; String s = null; Private string [] [] arrayValues; Path file path; Public Readfile (string name) {filePath = Paths.get ("C: \\ stock \\" + name); //newMSFT.csv System.out.println ("path to enter file" + filePath.toString ()); } Public Boolean file attributes () {if (Files.exists (filePath)) returns true; Second false return; } Public integer numberoffro (try {InputStream data = new BufferedInputStream (Files.newInputStream (filePath)); BufferedReader Reader = new BufferedReader (new InputStreamReader (data)); S = reader.readLine (); While (s! = Null) {Rows ++; S = reader.readLine ();}} Grip (Exception E) {System.out.println ("Message:" + E);} Return Rows;} Public Zero ConvertFileFile () {{ Try InputStream Data = New BufferedInputStream (Files.newInputStream (filePath)); BufferedReader Reader = New BufferedReader (New InputStreamReader (Data)); S = reader.readLine (); StringTokenZZ = New Str (Int x = 0; x and lt; rows; x ++) {z} for the string (rows); [string] [rows] [column]; for the string [z];); ArrayValues = new string [rows] [column]; = New StringTokenizer (S, ","); // When there are still more tokens, keep it in the array: int y = 0; while (z.hasMoreTokens ()) {array value [x] [y] = z .nextToken (); y ++;} S = reader.readLine ();} System.out.println ("An array was created and" + rows + "rows and" + column + "columns.); } Hold (exception e) {System.out.println ("Message:" + E); E.printStackTrace (); }} Public Zero printRay () {data from the system.out.println ("array is;;;);) (for int one = 0; one & lt; rows; a ++) {string output = zero; (Int b = 0; b & lt; column; b ++) {System.out.print (arrayValues [a] [b] + "");} System.out.println ();}} Public string [] [] getArrayValues () {return arrays;}}
IOException . Try
try {s = reader.readLine ();} hold (IOException e) {e.printStackTrace ();}
Invalid unauthorized Exception - If an invalid combination of options is specified
Unsupported operation exception - If an unsupported option is specified
IOException - If there is an I / O error
SecurityException - In the case of default provider, and a security manager has been installed, check the read read method in the file Is invited to check.
No comments:
Post a Comment