java - Why can't I open the input file when prompted? -


For this code, this is a Java text formatting program. I run it and then it indicates the size of the column, but then when it points to the file, then I type it and say it does not exist?

Am I doing something wrong?

> I tried to place the file location, and then the name of the file itself Should I try the same work place? help please.

Here's my code, if there are more internal problems then I'm ignoring. I thought it was working so far.

  import java.io. *; Import java.util.Scanner; / ** * Format - Simple Text Formatting * / Public Category Format {Public Fixed Zero Exit (Scanner Sc) • Press and hold the "// console window" until it is pressed 'if not' (if necessary). Println (); System.out.println ("Finish - Press the Enter key to end the program"); String junk = sc.nextLine (); System.exit (0); } / ** * main - text formatting * / public static zero main (string [] args) {scanner sc = new scanner (System.in); // Get the maximum output column for maximum maximum width; System.out.println ("Enter Output Column Width"); Do {maxWidth = sc.nextInt (); Sc.nextLine (); If (MaxWithth <30 || MaxWidth> 100) {System.out.println ("Column size should be between 30 and 100 ... re-enter"); MaxWide = 0; }} While (0 == MaxWith); // Get the name of the input text file to read and format, it exists, and check the readable. File text file = null; Scanner scan = null; Read the letter = null; String1 = ""; String textname; Do {System.out.println ("Enter the name of the input text file"); TextinName = sc.nextLine (); TextinFile = new file (textinName); If (! TextinFile.exists ()) {System.out.println ("File does not exist:" + textinName + "- re-enter"); TextinName = Null; to continue; } If (TextonFile.canRead ()) {System.out.println ("Unable to read from file:" + textinName + "- re-enter"); TextinName = Null; to continue; } {Scan = try new scanner (textfile); Scan = new scanner (new file (textName)); While (scan.hasNextLine ()) {read = scan.nextLine () + "\ n"; Read1 + = reading; } Scan.close (); } Hold (FileNotFoundException E) {// unexpected, as was already checked for the existing system .out.println ("unexpected error:" + e.toString ()); // text scanner = new scanner (textInfile); to continue; }} While (TextinFile.exists ()); // Get the name of the output file to write the formatted text, and open a file. String textname = null; Do {system.out.println ("Enter the name of the output file"); TextoutName = sc.nextLine (); File text filefile = new file (textoutname); If (textoutFile.exists ()) {System.out.println ("File already exists:" + textoutName); System.out.println ("Do you want to overwrite this file (Y / N)"); String yeah = sc.nextLine (); If (yesno.toLowerCase (). StartWith ("n")} {System.out.println ("Re-enter the output file name"); TextoutName = Null; to continue; }}} While (null == textoutName); // Open the output file to write (or console). Print-white textoutword = zero; Scanner OutputRadder = Faucet; String newReader = null; String newReader1 = ""; Try {// outputReader = new scanner (new file (textinName)); // text-word = new print-viter (new buffer vetter (new flumerwriter (textoutname)); Scanned = new scanner (textfile); Scan = new scanner (new file (textName)); While (scanHenname ()) {newReader = scan.next () + "\ n"; NewReader1 + = newReader; } Scan.close (); } Hold (IOException e) {System.out.println (e.toString ()); Exits (SC); } System.out.println ("\ n Looking at the following input file: \ n"); Println (read1); Specifying a formatted output width of "system.out.println (" \ n "+ maxWidth +" should produce the following output: \ n "); System.out.println ("The formatted output text is ... \ n"); {System.out.print ("*") for (int n = 0; n & lt; = maxWidth; n ++); } // Read the words from the input file, as long as the existing line is being added, the latest word output will be more than the column width, since the line is being created. // When the line is full, write it into the output file, and reset it to clear it. // Continue until the file ends. String word = ""; String line = ""; Println (""); Println (newReader1); }   

}

scanner.nxtain () contains ENTER at the end of the line, you have to remove that letter, then it should work.

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -