SlideShare a Scribd company logo
1 of 3
Class disp_filetypes { public static void main(String args[]) { Path dir = "C:mydir"; List list
Source Files(Path dir) throws IO Exception { List result = new Array List(); try (Directory
Stream stream = Files. new Directory Stream(dir, "*.{c,h,cpp,hppJava}")) { for (Path entry:
stream) { result. add(entry);}} catch (Directory lterator Exception ex) {//I/O error encounter
during the iteration, the cause is an IO Exception throw ex .get Cause();} for(i=0;i
Solution
Sequential version
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author prmsh
*/
public class disp_filetypes {
public static void main(String args[]) {
Path dir = "C:mydir";
List<Path.listSourceFiles
(Path dir) throws IOException {
List<Path> result = new ArrayList<>();
long startTime = System.currentTimeMillis();
try (DirectoryStrean<Path> stream
= Files.newDirectoryStream(dir, "*.{c,h,cpp,hpp,java}")) {
for (Path entry : stream) {
result.add(entry);
}
} catch (DirectoryIteratorException ex) {
throw ex.getCause();
}
for (int i = 0; i < result.size(); i++) {
System.out.println(result[i]);
}
long endTime = System.currentTimeMillis();
long totalTime = endTime - startTime;
//printing time taken
System.out.println(totalTime);
}
}
}
---------------------------------------------------------------------------------------------------------------------
-------------------------
Parallel version
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author prmsh
*/
public class disp_filetypes {
public static void main(String args[]) {
Path dir = "C:mydir";
List<Path.listSourceFiles
(Path dir) throws IOException {
List<Path> result = new ArrayList<>();
long startTime = System.currentTimeMillis();
try (DirectoryStrean<Path> stream
= Files.newDirectoryStream(dir, "*.{c,h,cpp,hpp,java}")) {
for (Path.parallelStream() entry : stream) {
result.add(entry);
}
} catch (DirectoryIteratorException ex) {
throw ex.getCause();
}
for (int i = 0; i < result.size(); i++) {
System.out.println(result[i]);
}
long endTime = System.currentTimeMillis();
long totalTime = endTime - startTime;
//printing time taken
System.out.println(totalTime);
}
}
}

More Related Content

Similar to Class disp_filetypes { public static void main(String args--) { Path d.docx

Modify the project so tat records are inserted into the random acess.pdf
Modify the project so tat records are inserted into the random acess.pdfModify the project so tat records are inserted into the random acess.pdf
Modify the project so tat records are inserted into the random acess.pdf
fcaindore
 
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdfModify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
arjuncorner565
 
please navigate to cs112 webpage and go to assignments -- Trees. Th.pdf
please navigate to cs112 webpage and go to assignments -- Trees. Th.pdfplease navigate to cs112 webpage and go to assignments -- Trees. Th.pdf
please navigate to cs112 webpage and go to assignments -- Trees. Th.pdf
aioils
 
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
Dmitry Soshnikov
 
Jedi Slides Intro2 Chapter12 Advanced Io Streams
Jedi Slides Intro2 Chapter12 Advanced Io StreamsJedi Slides Intro2 Chapter12 Advanced Io Streams
Jedi Slides Intro2 Chapter12 Advanced Io Streams
Don Bosco BSIT
 
I need hlep I have posted this proble 4 times have gotten no help can.pdf
I need hlep I have posted this proble 4 times have gotten no help can.pdfI need hlep I have posted this proble 4 times have gotten no help can.pdf
I need hlep I have posted this proble 4 times have gotten no help can.pdf
shreeaadithyaacellso
 
Frequency .java Word frequency counter package frequ.pdf
Frequency .java  Word frequency counter  package frequ.pdfFrequency .java  Word frequency counter  package frequ.pdf
Frequency .java Word frequency counter package frequ.pdf
arshiartpalace
 
--import statemnts for Random- Scanner and IO import java-util-Random-.pdf
--import statemnts for Random- Scanner and IO import java-util-Random-.pdf--import statemnts for Random- Scanner and IO import java-util-Random-.pdf
--import statemnts for Random- Scanner and IO import java-util-Random-.pdf
ganisyedtrd
 

Similar to Class disp_filetypes { public static void main(String args--) { Path d.docx (20)

Modify the project so tat records are inserted into the random acess.pdf
Modify the project so tat records are inserted into the random acess.pdfModify the project so tat records are inserted into the random acess.pdf
Modify the project so tat records are inserted into the random acess.pdf
 
Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams
 
Jug java7
Jug java7Jug java7
Jug java7
 
모던자바의 역습
모던자바의 역습모던자바의 역습
모던자바의 역습
 
Java8 - Interfaces, evolved
Java8 - Interfaces, evolvedJava8 - Interfaces, evolved
Java8 - Interfaces, evolved
 
A topology of memory leaks on the JVM
A topology of memory leaks on the JVMA topology of memory leaks on the JVM
A topology of memory leaks on the JVM
 
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdfModify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
 
Session 23 - JDBC
Session 23 - JDBCSession 23 - JDBC
Session 23 - JDBC
 
please navigate to cs112 webpage and go to assignments -- Trees. Th.pdf
please navigate to cs112 webpage and go to assignments -- Trees. Th.pdfplease navigate to cs112 webpage and go to assignments -- Trees. Th.pdf
please navigate to cs112 webpage and go to assignments -- Trees. Th.pdf
 
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
 
import java.io.BufferedReader; import java.io.IOException; impor.pdf
import java.io.BufferedReader; import java.io.IOException; impor.pdfimport java.io.BufferedReader; import java.io.IOException; impor.pdf
import java.io.BufferedReader; import java.io.IOException; impor.pdf
 
Java Class Design
Java Class DesignJava Class Design
Java Class Design
 
Jedi Slides Intro2 Chapter12 Advanced Io Streams
Jedi Slides Intro2 Chapter12 Advanced Io StreamsJedi Slides Intro2 Chapter12 Advanced Io Streams
Jedi Slides Intro2 Chapter12 Advanced Io Streams
 
I need hlep I have posted this proble 4 times have gotten no help can.pdf
I need hlep I have posted this proble 4 times have gotten no help can.pdfI need hlep I have posted this proble 4 times have gotten no help can.pdf
I need hlep I have posted this proble 4 times have gotten no help can.pdf
 
Frequency .java Word frequency counter package frequ.pdf
Frequency .java  Word frequency counter  package frequ.pdfFrequency .java  Word frequency counter  package frequ.pdf
Frequency .java Word frequency counter package frequ.pdf
 
C++17 std::filesystem - Overview
C++17 std::filesystem - OverviewC++17 std::filesystem - Overview
C++17 std::filesystem - Overview
 
--import statemnts for Random- Scanner and IO import java-util-Random-.pdf
--import statemnts for Random- Scanner and IO import java-util-Random-.pdf--import statemnts for Random- Scanner and IO import java-util-Random-.pdf
--import statemnts for Random- Scanner and IO import java-util-Random-.pdf
 
Java Programming - 06 java file io
Java Programming - 06 java file ioJava Programming - 06 java file io
Java Programming - 06 java file io
 
Anti patterns
Anti patternsAnti patterns
Anti patterns
 
Java 8 Workshop
Java 8 WorkshopJava 8 Workshop
Java 8 Workshop
 

More from tienlivick

The Kansas Early Learning Standards for Social and Emotional Developme.docx
The Kansas Early Learning Standards for Social and Emotional Developme.docxThe Kansas Early Learning Standards for Social and Emotional Developme.docx
The Kansas Early Learning Standards for Social and Emotional Developme.docx
tienlivick
 

More from tienlivick (20)

The long-term liability section of Twin Digital Corporation's balance.docx
The long-term liability section of Twin Digital Corporation's balance.docxThe long-term liability section of Twin Digital Corporation's balance.docx
The long-term liability section of Twin Digital Corporation's balance.docx
 
The length of time- in minutes- for an airplane to obtain clearance fo.docx
The length of time- in minutes- for an airplane to obtain clearance fo.docxThe length of time- in minutes- for an airplane to obtain clearance fo.docx
The length of time- in minutes- for an airplane to obtain clearance fo.docx
 
The Kansas Early Learning Standards for Social and Emotional Developme.docx
The Kansas Early Learning Standards for Social and Emotional Developme.docxThe Kansas Early Learning Standards for Social and Emotional Developme.docx
The Kansas Early Learning Standards for Social and Emotional Developme.docx
 
The Italian economy can be characterized by the following information-.docx
The Italian economy can be characterized by the following information-.docxThe Italian economy can be characterized by the following information-.docx
The Italian economy can be characterized by the following information-.docx
 
The individual that reports to the respective discipline manager- and.docx
The individual that reports to the respective discipline manager- and.docxThe individual that reports to the respective discipline manager- and.docx
The individual that reports to the respective discipline manager- and.docx
 
The Implementation The unique requirement for the SpecializedList is t.docx
The Implementation The unique requirement for the SpecializedList is t.docxThe Implementation The unique requirement for the SpecializedList is t.docx
The Implementation The unique requirement for the SpecializedList is t.docx
 
The imount liay ned to put aiay loday a f (Riound 13 en nemest cent).docx
The imount liay ned to put aiay loday a f (Riound 13 en nemest cent).docxThe imount liay ned to put aiay loday a f (Riound 13 en nemest cent).docx
The imount liay ned to put aiay loday a f (Riound 13 en nemest cent).docx
 
The hepcidin hormone acts as a negative regulator of iron absorption-.docx
The hepcidin hormone acts as a negative regulator of iron absorption-.docxThe hepcidin hormone acts as a negative regulator of iron absorption-.docx
The hepcidin hormone acts as a negative regulator of iron absorption-.docx
 
The Hardy-Weinberg principleapplies to which populations- Populations.docx
The Hardy-Weinberg principleapplies to which populations- Populations.docxThe Hardy-Weinberg principleapplies to which populations- Populations.docx
The Hardy-Weinberg principleapplies to which populations- Populations.docx
 
The Giant Kelp forests of the US Pacific coast have really cold water-.docx
The Giant Kelp forests of the US Pacific coast have really cold water-.docxThe Giant Kelp forests of the US Pacific coast have really cold water-.docx
The Giant Kelp forests of the US Pacific coast have really cold water-.docx
 
The function T(n) satisfies T(n)-2T(3n)+O(n2)- Which of the following.docx
The function T(n) satisfies T(n)-2T(3n)+O(n2)- Which of the following.docxThe function T(n) satisfies T(n)-2T(3n)+O(n2)- Which of the following.docx
The function T(n) satisfies T(n)-2T(3n)+O(n2)- Which of the following.docx
 
The following table summarizes the ages of a sample of 57 adults that.docx
The following table summarizes the ages of a sample of 57 adults that.docxThe following table summarizes the ages of a sample of 57 adults that.docx
The following table summarizes the ages of a sample of 57 adults that.docx
 
The following table presents output per hour in the country of Mistani.docx
The following table presents output per hour in the country of Mistani.docxThe following table presents output per hour in the country of Mistani.docx
The following table presents output per hour in the country of Mistani.docx
 
The following selected transactions occurred during 2024 and 2025 for.docx
The following selected transactions occurred during 2024 and 2025 for.docxThe following selected transactions occurred during 2024 and 2025 for.docx
The following selected transactions occurred during 2024 and 2025 for.docx
 
The following refer to the following data set- What is the mean (x) of.docx
The following refer to the following data set- What is the mean (x) of.docxThe following refer to the following data set- What is the mean (x) of.docx
The following refer to the following data set- What is the mean (x) of.docx
 
The following questions are based on the case study- The Human Right t.docx
The following questions are based on the case study- The Human Right t.docxThe following questions are based on the case study- The Human Right t.docx
The following questions are based on the case study- The Human Right t.docx
 
The following items are taken from the financial statements of Pharoah.docx
The following items are taken from the financial statements of Pharoah.docxThe following items are taken from the financial statements of Pharoah.docx
The following items are taken from the financial statements of Pharoah.docx
 
The following financial assets appeared in a recent balance sheet of A.docx
The following financial assets appeared in a recent balance sheet of A.docxThe following financial assets appeared in a recent balance sheet of A.docx
The following financial assets appeared in a recent balance sheet of A.docx
 
The following graph shows an aggregate demand (AD) curve and a short-r.docx
The following graph shows an aggregate demand (AD) curve and a short-r.docxThe following graph shows an aggregate demand (AD) curve and a short-r.docx
The following graph shows an aggregate demand (AD) curve and a short-r.docx
 
The first production department of Stone Incorporated reports the foll.docx
The first production department of Stone Incorporated reports the foll.docxThe first production department of Stone Incorporated reports the foll.docx
The first production department of Stone Incorporated reports the foll.docx
 

Recently uploaded

Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 

Recently uploaded (20)

Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 

Class disp_filetypes { public static void main(String args--) { Path d.docx

  • 1. Class disp_filetypes { public static void main(String args[]) { Path dir = "C:mydir"; List list Source Files(Path dir) throws IO Exception { List result = new Array List(); try (Directory Stream stream = Files. new Directory Stream(dir, "*.{c,h,cpp,hppJava}")) { for (Path entry: stream) { result. add(entry);}} catch (Directory lterator Exception ex) {//I/O error encounter during the iteration, the cause is an IO Exception throw ex .get Cause();} for(i=0;i Solution Sequential version import java.io.IOException; import java.nio.file.Path; import java.util.ArrayList; import java.util.List; /** * * @author prmsh */ public class disp_filetypes { public static void main(String args[]) { Path dir = "C:mydir"; List<Path.listSourceFiles (Path dir) throws IOException { List<Path> result = new ArrayList<>(); long startTime = System.currentTimeMillis(); try (DirectoryStrean<Path> stream = Files.newDirectoryStream(dir, "*.{c,h,cpp,hpp,java}")) { for (Path entry : stream) { result.add(entry); } } catch (DirectoryIteratorException ex) { throw ex.getCause(); } for (int i = 0; i < result.size(); i++) {
  • 2. System.out.println(result[i]); } long endTime = System.currentTimeMillis(); long totalTime = endTime - startTime; //printing time taken System.out.println(totalTime); } } } --------------------------------------------------------------------------------------------------------------------- ------------------------- Parallel version import java.io.IOException; import java.nio.file.Path; import java.util.ArrayList; import java.util.List; /** * * @author prmsh */ public class disp_filetypes { public static void main(String args[]) { Path dir = "C:mydir"; List<Path.listSourceFiles (Path dir) throws IOException { List<Path> result = new ArrayList<>(); long startTime = System.currentTimeMillis(); try (DirectoryStrean<Path> stream = Files.newDirectoryStream(dir, "*.{c,h,cpp,hpp,java}")) { for (Path.parallelStream() entry : stream) { result.add(entry); } } catch (DirectoryIteratorException ex) { throw ex.getCause(); } for (int i = 0; i < result.size(); i++) { System.out.println(result[i]); } long endTime = System.currentTimeMillis(); long totalTime = endTime - startTime; //printing time taken