Results 1 to 4 of 4
  1. #1
    java_prgr is offline Member
    Join Date
    Jul 2010
    Posts
    6
    Rep Power
    0

    Default reading a file and writing to a file....help!!!!

    here is my code:

    import java.util.*;
    import java.io.*;

    public class ReadFile {
    public static void manin(String[] args) throws FileNotFoundException {
    Scanner inFile = new Scanner(new FileReader("C:\\Users\\Usman\\Desktop\\employeeDat a.txt"));
    PrintWriter outFile = new PrintWriter("C:\\Users\\Usman\\Desktop\\wages.txt" );
    String Firstname, Lastname;
    double hours,payrate,wages;

    Firstname = inFile.next();
    Lastname = inFile.next();

    hours = inFile.nextDouble();
    payrate = inFile.nextDouble();

    wages = hours*payrate;

    outFile.println("$"+wages);

    inFile.close();
    outFile.close();

    }

    }

    Plz tell me what am i doing wrong in this. i want my file to be saved on the desktop and read from the desktop. the file that is being read is on my desktop but it is not being read, plz tell me y?

    also wat is my default directory, i cant find it?

  2. #2
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    I see two problems that catch my eye immediately:
    1. Your code is not in [code] tags.
    2. Your main method is misspelled:
    Java Code:
    public static void manin(String[] args) throws FileNotFoundException {
    Have not yet looked further; correct #2 and test your code to see if there's still an issue.

  3. #3
    java_prgr is offline Member
    Join Date
    Jul 2010
    Posts
    6
    Rep Power
    0

    Default

    zack, thnx alot. i actually feel embarrassed for such a dumb mistake. im so used to copying and pasting from a template, and the first time i actually wrote the main method statement, i mispelled.

    thnx again

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,899
    Rep Power
    25

    Default

    You must have gotten some error when you tried to execute the program without a valid main() method.
    Did you get an error?

    Normally errors mean something is wrong. You shouldn't ignore errors they often tell you how to fix the problem.

Similar Threads

  1. File reading / writing
    By MattBSibley in forum New To Java
    Replies: 5
    Last Post: 04-19-2010, 06:20 AM
  2. Replies: 9
    Last Post: 10-20-2009, 11:52 AM
  3. Replies: 3
    Last Post: 05-10-2009, 12:31 AM
  4. Reading and writing to a file
    By jigglywiggly in forum New To Java
    Replies: 13
    Last Post: 03-09-2009, 11:44 AM
  5. Help with File reading and writing
    By baltimore in forum New To Java
    Replies: 1
    Last Post: 07-31-2007, 07:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •