473,395 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Disk Reader Error

176 100+
Hello guys. I started learning about how to read information from disks and things.
I have a some code to start learning about it with. But when I run the code I get this error:

Exception in thread "main" java.io.FileNotFoundException: rawData.txt (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.jav a:106)
at java.util.Scanner.<init>(Scanner.java:621)
at readandwrite.Main.main(Main.java:26)

This is my code:
Expand|Select|Wrap|Line Numbers
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5.  
  6. package readandwrite;
  7.  
  8. /**
  9.  *
  10.  * @author Ned
  11.  */
  12. import java.util.Scanner;
  13. import java.io.File;
  14. import java.io.FileNotFoundException;
  15. import java.io.PrintStream;
  16.  
  17. public class Main {
  18.  
  19.     /**
  20.      * @param args the command line arguments
  21.      */
  22.     public static void main(String[] args) 
  23.         // TODO code application logic here
  24.  
  25.         throws FileNotFoundException {
  26.             Scanner diskScanner = new Scanner(new File("rawData.txt"));
  27.             PrintStream diskWriter = new PrintStream("cookedData.txt");
  28.             double unitPrice, quantity, total;
  29.  
  30.             unitPrice = diskScanner.nextDouble();
  31.             quantity = diskScanner.nextInt();
  32.  
  33.             total = unitPrice * quantity;
  34.  
  35.             diskWriter.println(total);
  36.  
  37.  
  38.         }
  39.     }
  40.  
May 15 '08 #1
2 1628
sukatoa
539 512MB
Hello guys. I started learning about how to read information from disks and things.
I have a some code to start learning about it with. But when I run the code I get this error:

Exception in thread "main" java.io.FileNotFoundException: rawData.txt (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.jav a:106)
at java.util.Scanner.<init>(Scanner.java:621)
at readandwrite.Main.main(Main.java:26)

This is my code:
Expand|Select|Wrap|Line Numbers
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5.  
  6. package readandwrite;
  7.  
  8. /**
  9.  *
  10.  * @author Ned
  11.  */
  12. import java.util.Scanner;
  13. import java.io.File;
  14. import java.io.FileNotFoundException;
  15. import java.io.PrintStream;
  16.  
  17. public class Main {
  18.  
  19.     /**
  20.      * @param args the command line arguments
  21.      */
  22.     public static void main(String[] args) 
  23.         // TODO code application logic here
  24.  
  25.         throws FileNotFoundException {
  26.             Scanner diskScanner = new Scanner(new File("rawData.txt"));
  27.             PrintStream diskWriter = new PrintStream("cookedData.txt");
  28.             double unitPrice, quantity, total;
  29.  
  30.             unitPrice = diskScanner.nextDouble();
  31.             quantity = diskScanner.nextInt();
  32.  
  33.             total = unitPrice * quantity;
  34.  
  35.             diskWriter.println(total);
  36.  
  37.  
  38.         }
  39.     }
  40.  
Base on your code, the rawData.txt should be at the same directory where your Main class exists...

The stackTrace says that the rawData.txt could not be found....
Have you check the directory of your .txt file?
May 15 '08 #2
Kid Programmer
176 100+
Base on your code, the rawData.txt should be at the same directory where your Main class exists...

The stackTrace says that the rawData.txt could not be found....
Have you check the directory of your .txt file?
That did it. Thanks!
May 15 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Stephen | last post by:
I'm having terrible trouble working out where I have gone wrong in my code below. In the data layer I have two methods and i'm basically returning a command and using it and then returning a...
1
by: Craig Beuker | last post by:
Hello, I am experimenting with this XmlValidatingReader and have a question about how it is working (or not working as would be the case) The sample documents and code are included at the end...
8
by: Todd Bright | last post by:
Is there a way to get the current XmlNode from the reader while in the validation event handler? What I'd like to do is display the error message along with the name of its parent node. In my...
1
by: Stephen | last post by:
I'm having terrible trouble working out where I have gone wrong in my code below. In the data layer I have two methods and i'm basically returning a command and using it and then returning a...
1
by: Aaron | last post by:
I asked for a script that can read info inside a specific xml tag and someone gave me this example. XmlReader reader = new XmlTextReader( filename ); while ( reader.Read() ) { if (...
2
by: Jas Shultz | last post by:
I'm using Win2K3 Enterprise edition with the latest .NET framework installed. I have this problem with getting "out of disk space" errors. I have 35 Gigs of disk space free. It doesn't happen...
8
by: Thirsty Traveler | last post by:
I have a dataset that is returned from a sql server select that contains metadata and a cached dataset saved in an xml column. I would like to recover the dataset for use in generating a crystal...
4
by: =?Utf-8?B?ZG1idXNv?= | last post by:
I have an Access database with a table named 'tblMedia'. In tblMedia I have a field named 'Media' that is defined as an 'OLE Ojbect' field. In this Media field, I have pictures, they are jpegs. I'm...
10
by: gary0gilbert | last post by:
An unusual spin to this recurring disk or network error in a Terminal Server environment. Access 2000, Terminal Server 2000, file server is windows 2000. All users have a separate copy of the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.