Messing up ;w; (Scanner sf = new Scanner(new File
(c:\\temp_Name\\FileName.in));) code. (BaseClass)
pSo the objective of the code that is shown here is to make it so that I
can create a generic class (Shell) for reading/processing files that also
includes a NumberFormat object as well as StringTokenizer and Scanner
objects. /p pHere is my code...../p precodeimport java.io.File; import
java.io.IOException; import java.util.StringTokenizer; import
java.util.Scanner; import java.text.NumberFormat; public class BaseClass {
public static void main (String args[]) throws IOException { NumberFormat
fmt = NumberFormat.getNumberInstance (); fmt.setMinimumFractionDigits(3);
//may need to change value fmt.setMaximumFractionDigits(3); //may need to
change value Scanner sf = new Scanner(new File
(c:\\temp_Name\\FileName.in)); int maxIndx = -1; // -1 so when we
increment below, the first index is 0 String text [] = new String[1000];
// to be safe, declare more that we need while (sf.hasNext()) { maxIndx++;
text[maxIndx] = sf.nextLine(); //System.out.println(text[maxIndx]); //
remove rem for testing } // maxIndx is now the highest index of text [].
Equals -1 if no text lines sf.close(); // We opened the file above, so
close it when finished // System.exit (0); // Use this just for testing
for (int j = 0; j lt;= maxIndx; j++) { StringTokenizer st = new
StringTokenizer (text[j] ); Scanner sc = new Scanner(text[j]);
System.out.println(text[j]); } } /code/pre p} /p pStack trace: /p
precodeException in thread main java.io.FileNotFoundException:
c:\temp_Name\FileName.in (The system cannot find the path specified) at
java.io.FileInputStream.open(Native Method) at
java.io.FileInputStream.lt;initgt;(FileInputStream.java:138) at
java.util.Scanner.lt;initgt;(Scanner.java:656) at
BaseClass.main(BaseClass.java:14) Java Result: 1 BUILD SUCCESSFUL (total
time: 0 seconds) – /code/pre
No comments:
Post a Comment