It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming Java Forum

FileNotFound

FileNotFound

Postby scarfacemontana on Fri Mar 02, 2007 1:22 am

Why is this program not finding the file

Code: Select all
import java.io.*;
import java.util.Scanner;

class OutFile
{
  public static void main(String[] args) throws IOException
  {
    String fileName;
    int n;
    String data;
    Scanner s = new Scanner(System.in);
   
    System.out.println("How many prices do you have?");
    n = s.nextInt();
    s.nextLine();
    System.out.println("What do you want to call you file of prices? ");
    fileName = s.nextLine();
   
    FileWriter fwriter = new FileWriter(fileName);
    PrintWriter outFile = new PrintWriter(fwriter);
   
    for(int i = 1; i <= n; i++)
    {
       System.out.println("Enter a price: ");
       data = s.nextLine();
       
       outFile.println(data);
    }
   
    outFile.close();
    System.out.println("Data written to file.");
  }
}
scarfacemontana
 
Posts: 0
Joined: Fri Mar 02, 2007 1:20 am

Postby mwa103 on Fri Mar 02, 2007 3:34 pm

Program works fine for me without modification (used out.txt for filename). Do you have write privileges in the folder where you are running the program? If so, what are you typing in for a filename?

-Mike
mwa103
100+ Club
 
Posts: 206
Joined: Mon Mar 07, 2005 10:55 pm


Who is online

Users browsing this forum: No registered users and 1 guest