Question

Using netbeans to write a program to create a file named CreateBinaryfile.txt if it does not...

Using netbeans to write a program to create a file named CreateBinaryfile.txt if it does not exist. Append new data to it if it already exists. Write 20 integers created randomly into the file using binary I/O. Thanks.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Random;

public class AppendBinaryFile {

    public static void main(String[] args) {
        File file = new File("CreateBinaryfile.txt");
        try {
            FileOutputStream fileOutputStream = new FileOutputStream(file, true);
            Random random = new Random();
            for (int i = 0; i < 20; i++) {
                fileOutputStream.write(String.valueOf(random.nextInt()).getBytes());
                fileOutputStream.write('\n');
            }
            fileOutputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Add a comment
Know the answer?
Add Answer to:
Using netbeans to write a program to create a file named CreateBinaryfile.txt if it does not...
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
  • (Create a binary data file) Write a program to create a file named CreateBinaryFile.dat if it...

    (Create a binary data file) Write a program to create a file named CreateBinaryFile.dat if it does not exist. Append new data to it if it already exists. Write 50 integers created randomly into the file using binary I/O.

  • (Create a text file) Write a program to create a file named Exercise17_01.txt if it does...

    (Create a text file) Write a program to create a file named Exercise17_01.txt if it does not exist. Append new data to it if it already exists. Write 150 integers created randomly into the file using text I/O. Integers are separated by a space.

  • Write a program to create a file named integerFile.txt if it does not exist. Write 100...

    Write a program to create a file named integerFile.txt if it does not exist. Write 100 integers created randomly into the file using text I/O. The random integers should be in the range 0 to 100 (including 0 and 100). Integers should be separated by spaces in the file. Read the data back from the file and display the data in increasing order This is what I have so far: import java.io.File; import java.util.Scanner; import java.io.PrintWriter; public class integerFile {...

  • : Files and Exceptions: Write a program to create and use a grade book for a...

    : Files and Exceptions: Write a program to create and use a grade book for a course. The gradebook is created as a file named as “Course_Name.dat” and includes the following information about students: Student ID, First Name, Last Name, and Grade. Assume the following structure for the gradebook file:1.Students’ records are separated by a new-line character.2.No field includes any white-space character, and fields are separated by space.3.The order of the fields is the same for all the records.Based on...

  • 3 Dn Ent Write a python program to create a Dictionary named grade with the given...

    3 Dn Ent Write a python program to create a Dictionary named grade with the given items and do the below operations: i. 15 i. Create Dictionary with keys-{'Monday', 'Tuesday', 'Wednesday Thursday', 'Friday') ii. values-{1, 2, 3, 4, 5) ii. Now append another item with key-'Saturday') and value-(63 to the already created Dictionary and print it.

  • Create a new NetBeans project from scratch named PowerDemo. Write a method that uses recursion to...

    Create a new NetBeans project from scratch named PowerDemo. Write a method that uses recursion to raise a number to a power. The method should accept two arguments: the number to be raised and the exponent. Assume that the exponent is a nonnegative integer. Demonstrate the method in a program. The main method will provide the testing code for using user input for the recursive method.

  • C++ 1. Your program should use named string constant for the file name to open the...

    C++ 1. Your program should use named string constant for the file name to open the file. Do not add any path to the file name because the path on your computer is not likely to exist on the computer the instructor uses to grade the program. Points may be deducted if you don't follow this instruction. 2. Split statements and comments longer than 80 characters into multiple lines and use proper indentations for the split portions. (Lab2b.cpp) Write a...

  • Using Spyder (or the IDE of choice), create a new file named Assignment1.py and write a...

    Using Spyder (or the IDE of choice), create a new file named Assignment1.py and write a Python program using the Editor that produces the following output: My name is Razan Abdelgalil. I am taking CIS 195 at Cabrini University. 1 + 1 = 2 (use an arithmetic operator for the calculation)

  • Write a line of code that will declare a file variable named data. Assuming that the...

    Write a line of code that will declare a file variable named data. Assuming that the variable data was correctly created in the previous problem, write a line of code that will associate the variable with a file named grades.txt that is being opened for reading. Assuming that grades.txt only contains integers, write a line of code that will use the variable data to read in the first integer and store in a variable named test1 that has already been...

  • Question 2: Assume that a text file containing a series of integers is named numbers.txt and...

    Question 2: Assume that a text file containing a series of integers is named numbers.txt and exists on the c:Temp. Write a program that reads all of the numbers stored in the file and calculates their total. In order to test this program, you may create a text file using notepad. No GUI is necessary. Name the program number.py

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