0% found this document useful (0 votes)
19 views

Lab Task 8

The document discusses multithreading and file operations in Java. It provides examples of creating threads to print numbers in order, creating thread objects to concurrently print ranges, and examples of file I/O like checking if a file exists, creating a file, writing to a file, and copying a file.

Uploaded by

sunnyleaon308
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Lab Task 8

The document discusses multithreading and file operations in Java. It provides examples of creating threads to print numbers in order, creating thread objects to concurrently print ranges, and examples of file I/O like checking if a file exists, creating a file, writing to a file, and copying a file.

Uploaded by

sunnyleaon308
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Topic: Multithreading and File

1. Create two threads, ThreadA and ThreadB. ThreadA should print odd numbers from
1 to 10, and ThreadB should print even numbers from 2 to 10. Ensure that the
numbers are printed in the correct order, and the output should look like: 1 2 3 4 5 6
7 8 9 10.
2. You want to print numbers from 1 to 10 using three separate threads. Each thread
should print a specific range of numbers, and the threads should run concurrently.
Like- thread1 prints 1-3, thread2 prints 4-7, thread3 prints 8-10.
3. Create a thread class which prints 1-n. Also create three objects of that class.
Implement the above scenario in Java, keeping in mind all kinds of exceptions
possible and ensure context switching. Show the expected output.

4. Write a Java program to get a list of all file/directory names from the given.
5. Write a Java program to check if a file or directory specified by pathname exists or
not.
6. Write a Java program to create a file of the name “student” inside a “university”
directory. And take input(at least 3) into that in- name, id, dept category. Read the
data from the file
7. Copy the data of file in number 3. To another file.

You might also like