Task 4: Text I/O public class Test { public static void main(String[] args) throws java.io.IOException { java.io.File fi

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Task 4: Text I/O public class Test { public static void main(String[] args) throws java.io.IOException { java.io.File fi

Post by answerhappygod »

Task 4: Text I/O
public class Test
{
public static void main(String[] args) throws java.io.IOException
{
java.io.File file = new java.io.File("……….."); //
create a text file called cars
if (file.exists())
{
System.out.println("File
already exists");
System.exit(0);
}
//
Create a file
java.io.PrintWriter output = new java.io.PrintWriter(…..);
//
Write formatted output to the file
output.print("Toyota
"); //model name
output.println(100000); //price
output.println("pink"); //color
output.print("………");
output.println(…………);
output.println("……..");
//
Close the file
output.close();
}}
import java.util.Scanner;
public class Test
{
public static void main(String[] args) throws java.io.IOException
{
java.io.File file = new java.io.File("……….");
// Create a Scanner for the file and name it
input
…………………………………………
// Read data from a file
while (input.hasNext())
{
String ModelName = input.next();
int ….. = ………………………..
String …. = …………………………..
System.out.println(
ModelName + "
" + Price + " " + Color);
}
// Close the file
input.close();
}
}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply