Question

How to create a file using Formatter? What happens if you exit the program without closing...

How to create a file using Formatter? What happens if you exit the program without closing it? What will happen if you are trying to write file onto a read only location? What will happen if you write to a file that has been closed? This question is related to Java programming. Please type answers. No screenshot of poorly written handwriting.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

>How to create a file using Formatter??

Java Formatter is a utility class that can make life simple when working with formatting stream output in Java. It is built to operate similarly to the C/C++ printf function. It is used to format and output data to a specific destionation, such as a string or a file output stream.

java.util.Formatter class provides support for layout justification and alignment, common formats for numeric, string, and date/time data, and locale- specific output.

So Formatter can not be used for creating a new file.

For creating a file we can use these 5 methods.

1. Using File class.

2. Using I/O streams

3. Using RandomAccessFile

4. Using NIO

5. Create a file and set POSIX Permissions

> What happens if you exit the program without closing it ??

It depends on how you exit. Under controlled cricumstances (via exit ( ) or a return from main( ) ) , the data in the ( output ) buffers will be flushed and the files closed in an orderly manner. Ohter resources that the process had will aslo be released.

If your program crashed out of control, or if it calls one of the alternative exit ( ) or Exit ( ) functions, then the system will still clean up (close) open file descriptors and release other resources, but the buffers won't be flushed, etc.

> What will happen if you are trying to write files onto a read only location?

It will throw a error like AccessDenied so we handle it by try() and chech() methods....

we can't do that because of security purpose.

I hope you got it.....

>  What will happen if you write to a file that has been closed?

After closing a file how can you write it because the resources of read and write was released so they are not more point to the location of the file. the pointer will free the from the memory which was pointing to that file memory.

so now pointer is having some garbage value....so where is write god knows.....

I hope I clear your doubts.....feel free to ask me in comments......and please like my answer..

Add a comment
Know the answer?
Add Answer to:
How to create a file using Formatter? What happens if you exit the program without closing...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • How do I create a simple java program file that opens and reads a file using...

    How do I create a simple java program file that opens and reads a file using java.io? I have the file Im supposed to open and read but I dont know how to code it to open and read the file?

  • Create a Java program that analyzes a program and produces the output into another file. The...

    Create a Java program that analyzes a program and produces the output into another file. The program must retrieve the path to the .java file. Once the path to the file is found the program must figure out the length of the longest line is in the program. For example, working with a program called MainFile.java. Once it figures out the longest line in the code it will put the output into MainFile.java.stats and it will be located in the...

  • Java Programming Part 1 File encryption is the science of writing the contents of a file...

    Java Programming Part 1 File encryption is the science of writing the contents of a file in a secret code. Your encryption program should work like a filter, reading the contents of one file, modifying the data into a code, and then writing the coded contents out to a second file. The second file will be a version of the first file, but written in a secret code. Although there are complex encryption techniques, you should come up with a...

  • Java Language Create file fports with the first line as a hostname that needs to be...

    Java Language Create file fports with the first line as a hostname that needs to be scanned for certain ports to be opened on it (the values shown are examples... you need to select your own values): host name 80 22 443 445 Write a java program to accomplish the following: Open file fports Read the hostname to be scanned and store it in variable hostname Read the ports into array of integers ports Create array status (of boolean type)...

  • Write a python program and pseudocode The Program Using Windows Notepad (or similar program), create a...

    Write a python program and pseudocode The Program Using Windows Notepad (or similar program), create a file called Numbers.txt in your the same folder as your Python program. This file should contain a list on floating point numbers, one on each line. The number should be greater than zero but less than one million. Your program should read the following and display: The number of numbers in the file (i.e. count them) (counter) The maximum number in the file (maximum)...

  • programming language is C++. Please also provide an explanation of how to create a file with...

    programming language is C++. Please also provide an explanation of how to create a file with the given information and how to use that file in the program Let's consider a file with the following student information: John Smith 99.0 Sarah Johnson 85.0 Jim Robinson 70.0 Mary Anderson 100.0 Michael Jackson 92.0 Each line in the file contains the first name, last name, and test score of a student. Write a program that prompts the user for the file name...

  • Description: Create a program called numstat.py that reads a series of integer numbers from a file...

    Description: Create a program called numstat.py that reads a series of integer numbers from a file and determines and displays the name of file, sum of numbers, count of numbers, average of numbers, maximum value, minimum value, and range of values. Purpose: The purpose of this challenge is to provide experience working with numerical data in a file and generating summary information. Requirements: Create a program called numstat.py that reads a series of integer numbers from a file and determines...

  • Java program Program: Grade Stats In this program you will create a utility to calculate and...

    Java program Program: Grade Stats In this program you will create a utility to calculate and display various statistics about the grades of a class. In particular, you will read a CSV file (comma separated value) that stores the grades for a class, and then print out various statistics, either for the whole class, individual assignments, or individual students Things you will learn Robustly parsing simple text files Defining your own objects and using them in a program Handling multiple...

  • Please help with program this. Thank you so much in advance! Create a Java program which...

    Please help with program this. Thank you so much in advance! Create a Java program which implements a simple stack machine. The machine has 6 instructions Push operand Puts a value on the stack. The operand is either a floating point literal or one of 10 memory locations designated MO M9 Pop operand Pops the value on the top of the stack and moves it to the memory location MO-M9 Add Pops the top two values off the stack, performs...

  • Java Programming Reading from a Text File Write a Java program that will use an object...

    Java Programming Reading from a Text File Write a Java program that will use an object of the Scanner class to read employee payroll data from a text file The Text file payroll.dat has the following: 100 Washington Marx Jung Darwin George 40 200 300 400 Kar Car Charles 50 22.532 15 30 The order of the data and its types stored in the file are as follows: Data EmployeelD Last name FirstName HoursWorked double HourlyRate Data Tvpe String String...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT