Eclipse compulation problem

  • From: "Gilbert Neiva" <gneiva@xxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Mon, 25 Oct 2010 13:49:36 -0600

I made a program that inputs information from one file and outputs it to 
another file. I am able to run it perfectly with the java console from the 
command prompt, But when I try to run it with Eclipse, I get the following 
error.

Exception in thread "main" java.io.FileNotFoundException: History.d1 (The 
system cannot find the file specified)

at java.io.FileInputStream.open(Native Method)

at java.io.FileInputStream.<init>(Unknown Source)

at java.io.FileInputStream.<init>(Unknown Source)

at java.io.FileReader.<init>(Unknown Source)

at History.getFile(History.java:14)

at History.main(History.java:19)



I don't know why it should run fine with the Java console, and why it should 
not run fine in Eclipse. The History.d1 which is the input file is in the 
output folder where the class file is. Can someone tell me what's going on? The 
source code for the application is below.



import java.io.*;
import java.util.Scanner; // Import Scanner class



public class History
{
 static Scanner inFile; // Declare Scanner object
 static PrintWriter outFile; // Declare PrintWriter object
 static String inputString; // Line of text from file
 static final String blanks = "     "; // String constant to indent paragraphs
  
 static void getFile() throws IOException
 {
  // Instantiating new scanner and new filereader object
  inFile = new Scanner(new FileReader("History.d1"));
  }
 
 public static void main(String[] args) throws IOException
 {
  getFile(); // Call method getFile() 


  

// Instantiating new printWriter and FileWriter object
  outFile = new PrintWriter(new FileWriter("history.d2"));




// Add blanks and first line

  inputString = blanks+inFile.nextLine(); 




// Print indented line to file  

outFile.println(inputString);



// Until there are no more lines to read

while (inFile.hasNextLine())
    {
   inputString = inFile.nextLine(); // Read in another line 

   

if (inputString.length() < 1) // If line is empty
   {
    inputString = inFile.nextLine(); // Read in another line
    if (inputString.length() < 1) // If line is empty
   {
    inputString = inFile.nextLine(); // Read in another line
   outFile.println("\n"); // Print blank line to file
   inputString = blanks+inputString; // Indent stored line with blanks
   outFile.println(inputString); // Print indented line to file
   }
    else // Otherwise
    {
    outFile.println("\n"); // Print blank line to file
     inputString = blanks+inputString; // Indent stored line with blanks 
     outFile.println(inputString); // Print indented line to file
    }
    }
     else // Otherwise
   {
    outFile.println(inputString); // Print line to file
  }
   }
  // Clos files
  inFile.close();
  outFile.close();
  
 // Print statement tells the user the application is fimished.
  System.out.println("Finished");
  }
 }




Gilbert Neiva

Other related posts: