Suppose you run the following
public class Test {
public static void main(String[] args)
throws java.io.IOExceptlon {
try (java.io.PrintWriter output =
new java.io.PrintWriter(“t.txt”); ){
output.printf(“%s”, “1234”);
output.printf(“%s”, “5678”);
output.close():
}
}
}
Want to see the full answer?
Check out a sample textbook solutionChapter 17 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version Plus MyProgrammingLab with Pearson EText -- Access Card Package
Additional Engineering Textbook Solutions
Programming in C
Modern Database Management
C++ How to Program (10th Edition)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Computer Science: An Overview (12th Edition)
Starting Out with Java: From Control Structures through Objects (6th Edition)
- There are six strings of length 4 which cannot be produced by the following regular expression over the alphabet Σ = {a, b}. What are they? (a+bb)*(ab+ba) (aa + b)* Please select file(s) Select file(s)arrow_forwardPlease write a Java program , to write data into a file ( output.txt ). The output.txt file is below. 1 22 333 4444 55555 666666arrow_forwardWrite a program that reads lines of characters froma text file and writes each line as a UTF string into a binary file. Display thesizes of the text file and the binary file. Use the following command to run theprogram:java Exercise17_04 Welcome.java Welcome.utfarrow_forward
- 2. Suppose that you are implementing a program to write a string "CSE SS0" in a binary file. Java provides you three different methods – writeBytes(String), writeChars(String), and writeUTF(String). How many bytes will be written by each of those method for the give string? Which method did you find as the most efficient?arrow_forwardPlease answer and write algorithmarrow_forwardWrite the java program that will prdoce the output belowarrow_forward
- 1. Write a Java program that reads the file "input.txt" and calculates and prints the average of all integer numbers in this file. SAMPLE OUTPUT: throws FileNotFoundException try/catch OUTPUT SAMPLE #1 for input.txt: 1 2 3 4 5 6 x x x 8 12 x x 34 x x 10 20 Please input the name of the file to be opened: input.tx --- File Not Found! OUTPUT SAMPLE #1 for input.txt: 1 2 OUTPUT SAMPLE #2 for input.txt: 1 2 3 4 5 6 x x x 8 12 x x 34 x x 10 20 Please input the name of the file to be opened: input.txt Number # 1 is: 1 Number # 2 is: 2 3 4 5 6 x x x 8 12 x x 34 x x 10 20 Number # 1 is: 1 Number # 2 is: 2 Number # 3 is: 3 Number # 4 is: 4 Number # 5 is: 5 Number # 6 is: 6 Number # 3 is: 3 Number # 4 is: 4 Number # 5 is: 5 Number # 7 is: 8 Number # 8 is: 12 Number # 9 is: 34 Number # 6 is: 6 Number # 10 is: 10 Number # 7 is: 8 Number # 11 is: 20 The average of 11 numbers/file = 9.55 Number # 8 is: 12 Number # 9 is: 34 Number # 10 is: 10 OUTPUT SAMPLE #2 for Number # 11 is: 20 The average of 11…arrow_forwardRun this program and show the outputarrow_forwardpython: Open the file mbox-short.txt and read it line by line. When you find a line that starts with 'From ' like the following line:From stephen.marquard@uct.ac.za Sat Jan 5 09:14:16 2008 You will parse the From line using split() and print out the second word in the line (i.e. the entire address of the person who sent the message). Then print out a count at the end. Hint: make sure not to include the lines that start with 'From:'. Also look at the last line of the sample output to see how to print the count. You can download the sample data at http://www.py4e.com/code3/mbox-short.txt my code: fname = input("Enter file name: ")if len(fname) < 1: fname = "mbox-short.txt" fh = open(fname)count = 0 print("There were", count, "lines in the file with From as the first word")arrow_forward
- Using JAVA, write a program that reds a file containing two columns of floating-point numbers. Prompt the user for a file name. Print the average of each column on screen as well as a separate file.arrow_forwardUsing Java PrintWriter, write a program that prompts the user for information and saves it to a text file File name is musicians.txt Use this information below: George,Thoroughgood,54321 Ludwig,Van Beethoven,90111 Edward,Van Halen,12345arrow_forwardModify the code so that it writes the contents of String[] into a file named fileLoop1.txt CODE import java.util.Scanner; import java.io.*; public class Stringio { public static void main(String[] args) throws IOException { File loopfile = new File("fileLoop.txt"); Scanner getAll = new Scanner( loopfile ); String num; String[] items = new String[10]; int i = 0; while(getAll.hasNextLine()){ num = getAll.nextLine(); // square = num * num ; //System.out.println("The square of " + num + " is " + square); items[i] = num; System.out.println("items[i] is " + items[i]); i = i + 1; } getAll.close(); } }arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT