将文件复制到目录时遇到问题。
这是我编写的代码
package icecream1;
import java.nio.file.Paths;
/**
*
* @author
*/
public class Icecream1 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try {
TextIO.readFile("icecream.txt"); // open file
System.out.println("Please make sure the file is present before");
System.out.println("running the program.");
System.exit(1); // Terminates the program.
}
catch (IllegalArgumentException e) {
System.out.println("Can't open file \"icecream.txt\" for reading!");
}
int numberCones = 1; // stores total number of cones
int numberStrawberry = 1; // stores total number of strawberry cones
double percent;
while (TextIO.eof()) { // read one line
String data; // stores icecream flavor
data = TextIO.getln(); // read a line
numberCones += 1; // increment count
if (data.equals("Strawberry"))
numberStrawberry += 1;
} // while
//calculate percent of strawberry icecream
percent = 100.0 * numberStrawberry / numberCones;
//display result
String ourDirectory = Paths.get(".").toAbsolutePath().normalize().toString();
TextIO.readFile(ourDirectory + "//dist//icecream.txt");
System.out.println(TextIO.getlnString());
System.out.println("The total Number of cones: " + numberCones);
System.out.println("The total Number of Strawberry cones: " + numberStrawberry);
System.out.println("The total Percentage of Strawberry cones: " + percent + " %");
// TODO code application logic here
}
}
package icecream1;
import java.nio.file.Paths;
/**
*
* @author
*/
public class Icecream1 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try {
TextIO.readFile("icecream.txt"); // open file
System.out.println("Please make sure the file is present before");
System.out.println("running the program.");
System.exit(1); // Terminates the program.
}
catch (IllegalArgumentException e) {
System.out.println("Can't open file \"icecream.txt\" for reading!");
}
int numberCones = 1; // stores total number of cones
int numberStrawberry = 1; // stores total number of strawberry cones
double percent;
while (TextIO.eof()) { // read one line
String data; // stores icecream flavor
data = TextIO.getln(); // read a line
numberCones += 1; // increment count
if (data.equals("Strawberry"))
numberStrawberry += 1;
} // while
//calculate percent of strawberry icecream
percent = 100.0 * numberStrawberry / numberCones;
//display result
String ourDirectory = Paths.get(".").toAbsolutePath().normalize().toString();
TextIO.readFile(ourDirectory + "//dist//icecream.txt");
System.out.println(TextIO.getlnString());
System.out.println("The total Number of cones: " + numberCones);
System.out.println("The total Number of Strawberry cones: " + numberStrawberry);
System.out.println("The total Percentage of Strawberry cones: " + percent + " %");
// TODO code application logic here
}
}
无法打开文件“ icecream.txt”以供阅读!