Question

In: Computer Science

In writing integers to a file you need to connect 2 streams together to accomplish this...

In writing integers to a file you need to connect 2 streams together to accomplish this task. Below show the code you might use to connect 2 stream classes together. (Use a FileOutputStream and a DataOutputStream)

Solutions

Expert Solution

Code:

public class FileExample {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
     try{    String path1="E:\\intwritingex.txt" ;
             FileOutputStream fout=new FileOutputStream(path1);    //path1 is file pathname
             DataOutputStream ds = new DataOutputStream(fout); //connectting ds stream to file stream
        ds.writeInt(1); //writing usig ds as integer not possible in ordinary file much easily integer is wirtten in as hexacedimal in file not decimal
        ds.flush(); //FLUSH IS USED FOR FORCED WRITING
     
        ds.close() ;//closoiign data stream
        fout.close();//closing file steam
        System.out.println("operations perfomed succesfully");
            }catch(Exception e){System.out.println("FILE CANNOT BE OPENED");}  
      }//end of main  
    }//end of class

Word of caution datastream writeInt writes integer in hexadecimal format to file

Output:

Code ScreenShot


Related Solutions

You need to connect two buildings across a public road, and it is not feasible to...
You need to connect two buildings across a public road, and it is not feasible to use a direct cable connection. Under what circumstances would you use a microwave link? A radio link? an infrared laser link? What about the other wireless alternatives?
This is the full questions no more details. take any amount you need to accomplish this...
This is the full questions no more details. take any amount you need to accomplish this problem. 1. Choose a salary that you want to have at age 25. Assume that you get raises that keep up with the cost of inflation. Assume that you contribute 10% of your income to your retirement plan. Assume your own rate of return on your money. How much do you need to have saved if you retire at 40 and live to 90?...
A sequential file contains at most four billion 32-bit integers in random order, we need to...
A sequential file contains at most four billion 32-bit integers in random order, we need to find a 32-bit integer that isn’t in the file. Note that certainly we can simply read them all into memory (if we have enough memory) and sort them. That would cost O(n log n) for sorting and O(n) for searching. Think if we do better than that WITHOUT sorting and answer the following questions with better solutions. (a) Explain why there must be at...
For this writing task, you'll need to respond to the following scenario: Who are you? You...
For this writing task, you'll need to respond to the following scenario: Who are you? You work as department head in the information technology (IT) department at First Federal Bank. Part of your job is to conduct an ongoing assessment of risk for the institution and to recommend proper controls. Banking systems should be able to quickly collect and edit information, summarize results, and promptly correct any errors. You have identified a possible threat to "timeliness" of information. You have...
Task 2: Debugging and writing functions In IDLE, use the File -> New Window menu option...
Task 2: Debugging and writing functions In IDLE, use the File -> New Window menu option to open a new editor window for your program, and save it using the name hw4Task2.py. Make sure to specify the .py extension. Copy the following (buggy) code into that file: def mysum(x, y) """ takes two numbers and returns their sum """     total = x + y     print(total) Save the file using Ctrl-S. Then try to run it using F5. What...
you need to submit the following files: Main.java Additionally, you need to download file ‘letter_count.csv’, that...
you need to submit the following files: Main.java Additionally, you need to download file ‘letter_count.csv’, that contains counts for characters in a text (see submission folder on iCollege) and put it into the root of related Eclipse project folder. To view your project folder through system file explorer, right-click on ‘src’ folder in the Eclipse project explorer and choose ‘Show In->System Explorer’. Consider the following Java code, that reads a .csv file: BufferedReader csvReader = new BufferedReader(new FileReader("letter_count.csv")); String currentRow...
For this question you will need to upload a file. It is question 3 from the...
For this question you will need to upload a file. It is question 3 from the PDF file I sent you. Please show your work. The following information is given about the market for a normal good. Demand: P = 150-2Qd Supply P = 20+ 0.5 Qs What is the quantity demanded at a price of $80? (1.5 mark) What is the quantity supplied at a price of $80? (1.5 mark) At a price of $80 the market is not...
You will need the information in this file to complete the two lab sequence This is...
You will need the information in this file to complete the two lab sequence This is the file that contains the report page for Lab 13-Taste, part 1 There are two things for you to turn in Enter your taste data on the following page. You should all be able to edit and save the page. Lab #13 - Taste Data W18 Taste Background Background Introduction Taste is the least understood of all the senses. (PBS, 2000) Taste has been...
You need to write a program that reads in two integers from cin and outputs an...
You need to write a program that reads in two integers from cin and outputs an horribly inefficent calculation of the median value. First count from the first number to the second, but stop one short. Then, count from that number back towards the first, again stopping one short. Continue until you reach a single number. Enter 3 and 9 solution: 3456789 987654 45678 8765 567 76 6
You need to write a program that reads in two integers from cin and outputs an...
You need to write a program that reads in two integers from cin and outputs an horribly inefficent calculation of the median value. First count from the first number to the second, but stop one short. Then, count from that number back towards the first, again stopping one short. Continue until you reach a single number.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT