Thanks in advance
Hey guys, Im having some trouble with a simple file IO program, its supposed to just read the file then print the results to the output. I think that its more a problem of me not placing the data.txt file in the correct directory.
For example in windows i get the file not found error even though its technically in the same location as when i run it in ubuntu (Just within the FileIO project file with all of the src and dist directories). But for some reason when i run main in ubuntu it works perfectly and can find data.txt :S However when i build a .java in ubuntu (and copy the same data.txt into the same directory as the .java) it wont run and states file not found?
Any help is greatly appreciated! and heres the code and directory trees
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package fileio;
import java.util.Scanner;
import java.text.DecimalFormat;
import java.io.*;
/**
*
* @author sredman
*/
public class Main
{
public static void main(String[] args) throws IOException
{
System.out.println(new File(".").getAbsolutePath());
Scanner inputFile;
inputFile = new Scanner(new File("data.txt"));
DecimalFormat myformat = new DecimalFormat("0.##");
String name;
float price;
price = inputFile.nextFloat();
inputFile.nextLine();
while (price != 0)
{
name = inputFile.nextLine();
System.out.println(name + " -- " + myformat.format(price));
price = inputFile.nextFloat();
inputFile.nextLine();
}
}
}
|-FileIO
|---build
|-----classes
|-------fileio
|-----empty
|---dist
|---nbproject
|-----private
|---src
|-----fileio
|---test

New Topic/Question
Reply



MultiQuote



|