0% found this document useful (0 votes)
18 views2 pages

Lab1 Java Fullstack

The Java program creates a folder and a text file containing an essay about multitasking operating systems. It counts the number of words in the essay and the number of sentences read from the file. Finally, it outputs these counts to the console along with the content of the essay.

Uploaded by

karshuhana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views2 pages

Lab1 Java Fullstack

The Java program creates a folder and a text file containing an essay about multitasking operating systems. It counts the number of words in the essay and the number of sentences read from the file. Finally, it outputs these counts to the console along with the content of the essay.

Uploaded by

karshuhana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import java.util.Scanner; import java.io.

*;
import java.time.DayOfWeek;

public class TextFileDemo {

public static void main(String[] args) throws IOException {

//find number of words present in essay


// find number of sentences
// generate score as no_of_sentences + no_of_words
// copy the above file to a new location
// read the content to console

//File class is used to create a folder as well file

// File file = new File("C:\\Tmahindra");


// file.mkdir();
// System.out.println("Folder created ");
//
// Scanner scanner = new Scanner(System.in);
// System.out.println("enter the name of the file");
// String filename = scanner.nextLine();
//
//
// File obj = new File("C:\\Tmahindra\\"+filename+".txt");
//
// // use of file writer class
// FileWriter fWriter = new FileWriter(obj);
//
// fWriter.write("hi");
// fWriter.close();
// System.out.println("file created and written");

File file = new File("C:\\AyushFolder");


file.mkdir();

System.out.println("folder created");

Scanner scanner = new Scanner(System.in);


String fileString = "essay.txt";
File objFile =new File("C:\\AyushFolder\\"+fileString);
FileWriter fWriter = new FileWriter(objFile);
String contentString = "A single-tasking system can only run one
program at a time, while a multi-tasking operating system allows more than one
program to be running concurrently.\n This is achieved by time-sharing, where the
available processor time is divided between multiple processes.\n These processes
are each interrupted repeatedly in time slices by a task-scheduling subsystem of
the operating system.\n Multi-tasking may be characterized in preemptive and
cooperative types.\n In preemptive multitasking, the operating system slices the
CPU time and dedicates a slot to each of the programs.\n Unix-like operating
systems, such as Linux—as well as non-Unix-like, such as AmigaOS—support preemptive
multitasking.\n Cooperative multitasking is achieved by relying on each process to
provide time to the other processes in a defined manner.\n 16-bit versions of
Microsoft Windows used cooperative multi-tasking; 32-bit versions of both Windows
NT and Win9x used preemptive multi-tasking.";
String []contentarr = contentString.split(" ");

int no_of_words = contentarr.length;


System.out.println(no_of_words+"\n\n");
fWriter.write(contentString);
fWriter.close();

FileReader fileReader = new FileReader(objFile);


BufferedReader br = new BufferedReader(fileReader);

String st;
int count =0;

while ((st = br.readLine()) != null) {


System.out.println(st);
count++;
}

System.out.println("\n\n\n\n no_of_words = "+no_of_words + " "+ " no of


sentences = "+ count);

You might also like