SlideShare a Scribd company logo
1 of 2
Download to read offline
Java Program using Recursion:
Write a program that reads in a file and outputs it to another file. The output file created should
be identical to the input file but with its lines in reverse order. Use recursion. Obtain the names
of the input and output files from the command line. For the input file, use a file that contains the
integers 1 to 10, each on a seperate line.
Solution
I think the given code is working correctly
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.RandomAccessFile;
import java.io.Reader;
public class Reversefile {
public static void main(String[] args) {
FileInputStream fis = null;
RandomAccessFile raf = null;
String characterEncoding = "utf-8";
if(args.length==3) {
characterEncoding = args[2];
}
try{
File in = new File(args[0]);
fis = new FileInputStream(in);
Reader r = new InputStreamReader(fis,characterEncoding);
File out = new File(args[1]);
raf = new RandomAccessFile(out, "rw");
raf.setLength(in.length());
char[] buff = new char[1];
long position = in.length();
while((r.read(buff))>-1) {
Character c = buff[0];
String s = c+"";
byte[] bBuff = s.getBytes(characterEncoding);
position = position-bBuff.length;
raf.seek(position);
raf.write(bBuff);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
fis.close();
} catch (Exception e2) {
}
try {
raf.close();
} catch (Exception e2) {
}
}
}
}

More Related Content

Similar to Java Program using RecursionWrite a program that reads in a file .pdf

In JavaWrite a program that reads a file and counts how many line.pdf
In JavaWrite a program that reads a file and counts how many line.pdfIn JavaWrite a program that reads a file and counts how many line.pdf
In JavaWrite a program that reads a file and counts how many line.pdfsuresh640714
 
Understanding java streams
Understanding java streamsUnderstanding java streams
Understanding java streamsShahjahan Samoon
 
File Handling in Java.pdf
File Handling in Java.pdfFile Handling in Java.pdf
File Handling in Java.pdfSudhanshiBakre1
 
In JavaWrite a program that reads a text file that contains a gra.pdf
In JavaWrite a program that reads a text file that contains a gra.pdfIn JavaWrite a program that reads a text file that contains a gra.pdf
In JavaWrite a program that reads a text file that contains a gra.pdfmumnesh
 
Description 1) Create a Lab2 folder for this project2.docx
Description       1)  Create a Lab2 folder for this project2.docxDescription       1)  Create a Lab2 folder for this project2.docx
Description 1) Create a Lab2 folder for this project2.docxtheodorelove43763
 
I need help with this Java assignment. Please include comments throu.pdf
I need help with this Java assignment. Please include comments throu.pdfI need help with this Java assignment. Please include comments throu.pdf
I need help with this Java assignment. Please include comments throu.pdfsales98
 
Write a program in java that asks a user for a file name and prints .pdf
Write a program in java that asks a user for a file name and prints .pdfWrite a program in java that asks a user for a file name and prints .pdf
Write a program in java that asks a user for a file name and prints .pdfatulkapoor33
 
Change the code in Writer.java only to get it working. Must contain .pdf
Change the code in Writer.java only to get it working. Must contain .pdfChange the code in Writer.java only to get it working. Must contain .pdf
Change the code in Writer.java only to get it working. Must contain .pdfsecunderbadtirumalgi
 
Files & IO in Java
Files & IO in JavaFiles & IO in Java
Files & IO in JavaCIB Egypt
 
Use Java to program the following.1. Create public java class name.pdf
Use Java to program the following.1. Create public java class name.pdfUse Java to program the following.1. Create public java class name.pdf
Use Java to program the following.1. Create public java class name.pdff3apparelsonline
 
Java session08
Java session08Java session08
Java session08Niit Care
 
Write a program CountWords in Java that reads text from a file and b.pdf
Write a program CountWords in Java that reads text from a file and b.pdfWrite a program CountWords in Java that reads text from a file and b.pdf
Write a program CountWords in Java that reads text from a file and b.pdfrushabhshah600
 
Advance C Programming UNIT 4-FILE HANDLING IN C.pdf
Advance C Programming UNIT 4-FILE HANDLING IN C.pdfAdvance C Programming UNIT 4-FILE HANDLING IN C.pdf
Advance C Programming UNIT 4-FILE HANDLING IN C.pdfsangeeta borde
 
JAVA Q2- Write a program that reads strings from the user and writes t.docx
JAVA Q2- Write a program that reads strings from the user and writes t.docxJAVA Q2- Write a program that reads strings from the user and writes t.docx
JAVA Q2- Write a program that reads strings from the user and writes t.docxmichael1810
 

Similar to Java Program using RecursionWrite a program that reads in a file .pdf (20)

In JavaWrite a program that reads a file and counts how many line.pdf
In JavaWrite a program that reads a file and counts how many line.pdfIn JavaWrite a program that reads a file and counts how many line.pdf
In JavaWrite a program that reads a file and counts how many line.pdf
 
Java file
Java fileJava file
Java file
 
Understanding java streams
Understanding java streamsUnderstanding java streams
Understanding java streams
 
File Handling in Java.pdf
File Handling in Java.pdfFile Handling in Java.pdf
File Handling in Java.pdf
 
In JavaWrite a program that reads a text file that contains a gra.pdf
In JavaWrite a program that reads a text file that contains a gra.pdfIn JavaWrite a program that reads a text file that contains a gra.pdf
In JavaWrite a program that reads a text file that contains a gra.pdf
 
Description 1) Create a Lab2 folder for this project2.docx
Description       1)  Create a Lab2 folder for this project2.docxDescription       1)  Create a Lab2 folder for this project2.docx
Description 1) Create a Lab2 folder for this project2.docx
 
I need help with this Java assignment. Please include comments throu.pdf
I need help with this Java assignment. Please include comments throu.pdfI need help with this Java assignment. Please include comments throu.pdf
I need help with this Java assignment. Please include comments throu.pdf
 
Write a program in java that asks a user for a file name and prints .pdf
Write a program in java that asks a user for a file name and prints .pdfWrite a program in java that asks a user for a file name and prints .pdf
Write a program in java that asks a user for a file name and prints .pdf
 
Change the code in Writer.java only to get it working. Must contain .pdf
Change the code in Writer.java only to get it working. Must contain .pdfChange the code in Writer.java only to get it working. Must contain .pdf
Change the code in Writer.java only to get it working. Must contain .pdf
 
Files & IO in Java
Files & IO in JavaFiles & IO in Java
Files & IO in Java
 
Use Java to program the following.1. Create public java class name.pdf
Use Java to program the following.1. Create public java class name.pdfUse Java to program the following.1. Create public java class name.pdf
Use Java to program the following.1. Create public java class name.pdf
 
Functions in python
Functions in pythonFunctions in python
Functions in python
 
Java session08
Java session08Java session08
Java session08
 
Write a program CountWords in Java that reads text from a file and b.pdf
Write a program CountWords in Java that reads text from a file and b.pdfWrite a program CountWords in Java that reads text from a file and b.pdf
Write a program CountWords in Java that reads text from a file and b.pdf
 
C Programming Unit-5
C Programming Unit-5C Programming Unit-5
C Programming Unit-5
 
JAVA
JAVAJAVA
JAVA
 
Unit 5 dwqb ans
Unit 5 dwqb ansUnit 5 dwqb ans
Unit 5 dwqb ans
 
file_handling_in_c.ppt
file_handling_in_c.pptfile_handling_in_c.ppt
file_handling_in_c.ppt
 
Advance C Programming UNIT 4-FILE HANDLING IN C.pdf
Advance C Programming UNIT 4-FILE HANDLING IN C.pdfAdvance C Programming UNIT 4-FILE HANDLING IN C.pdf
Advance C Programming UNIT 4-FILE HANDLING IN C.pdf
 
JAVA Q2- Write a program that reads strings from the user and writes t.docx
JAVA Q2- Write a program that reads strings from the user and writes t.docxJAVA Q2- Write a program that reads strings from the user and writes t.docx
JAVA Q2- Write a program that reads strings from the user and writes t.docx
 

More from duttakajal70

Explain the relevance of the rules against hearsay to digital eviden.pdf
Explain the relevance of the rules against hearsay to digital eviden.pdfExplain the relevance of the rules against hearsay to digital eviden.pdf
Explain the relevance of the rules against hearsay to digital eviden.pdfduttakajal70
 
Electric and magnetic fields in an electromagnetic wave are alway.pdf
Electric and magnetic fields in an electromagnetic wave are alway.pdfElectric and magnetic fields in an electromagnetic wave are alway.pdf
Electric and magnetic fields in an electromagnetic wave are alway.pdfduttakajal70
 
C# code pleaseWrite a program that creates a link list object of 1.pdf
C# code pleaseWrite a program that creates a link list object of 1.pdfC# code pleaseWrite a program that creates a link list object of 1.pdf
C# code pleaseWrite a program that creates a link list object of 1.pdfduttakajal70
 
During our laboratory exercise on cellular the Krebs cycle in.pdf
During our laboratory exercise on cellular the Krebs cycle in.pdfDuring our laboratory exercise on cellular the Krebs cycle in.pdf
During our laboratory exercise on cellular the Krebs cycle in.pdfduttakajal70
 
25. On January 3, Pippin Corporation purchased 1,900 shares of the c.pdf
25. On January 3, Pippin Corporation purchased 1,900 shares of the c.pdf25. On January 3, Pippin Corporation purchased 1,900 shares of the c.pdf
25. On January 3, Pippin Corporation purchased 1,900 shares of the c.pdfduttakajal70
 
Define filtration and active transport.SolutionFiltration is t.pdf
Define filtration and active transport.SolutionFiltration is t.pdfDefine filtration and active transport.SolutionFiltration is t.pdf
Define filtration and active transport.SolutionFiltration is t.pdfduttakajal70
 
Why wouldnt you want to post a payment against an invoice directly.pdf
Why wouldnt you want to post a payment against an invoice directly.pdfWhy wouldnt you want to post a payment against an invoice directly.pdf
Why wouldnt you want to post a payment against an invoice directly.pdfduttakajal70
 
Cisco routers and switches use two configuration files. Where is the.pdf
Cisco routers and switches use two configuration files. Where is the.pdfCisco routers and switches use two configuration files. Where is the.pdf
Cisco routers and switches use two configuration files. Where is the.pdfduttakajal70
 
Which of the following is a simple compressible system A mixtur.pdf
Which of the following is a simple compressible system  A mixtur.pdfWhich of the following is a simple compressible system  A mixtur.pdf
Which of the following is a simple compressible system A mixtur.pdfduttakajal70
 
Which of the following statements is (are) trueI Walls Street i.pdf
Which of the following statements is (are) trueI  Walls Street i.pdfWhich of the following statements is (are) trueI  Walls Street i.pdf
Which of the following statements is (are) trueI Walls Street i.pdfduttakajal70
 
What would be the most effective method of reducing the incidence of .pdf
What would be the most effective method of reducing the incidence of .pdfWhat would be the most effective method of reducing the incidence of .pdf
What would be the most effective method of reducing the incidence of .pdfduttakajal70
 
What is a micelle What is a vesicle How are these structures the s.pdf
What is a micelle What is a vesicle How are these structures the s.pdfWhat is a micelle What is a vesicle How are these structures the s.pdf
What is a micelle What is a vesicle How are these structures the s.pdfduttakajal70
 
To determine her breathing rate, Miranda divides up her day into thre.pdf
To determine her breathing rate, Miranda divides up her day into thre.pdfTo determine her breathing rate, Miranda divides up her day into thre.pdf
To determine her breathing rate, Miranda divides up her day into thre.pdfduttakajal70
 
On January 29th, 2014, the Royal Caribbean cruise ship Explorer of.pdf
On January 29th, 2014, the Royal Caribbean cruise ship Explorer of.pdfOn January 29th, 2014, the Royal Caribbean cruise ship Explorer of.pdf
On January 29th, 2014, the Royal Caribbean cruise ship Explorer of.pdfduttakajal70
 
Name and describe the six main types of lymphatic cells, discuss the.pdf
Name and describe the six main types of lymphatic cells, discuss the.pdfName and describe the six main types of lymphatic cells, discuss the.pdf
Name and describe the six main types of lymphatic cells, discuss the.pdfduttakajal70
 
Let X1, X2, . . . , Xn be n independent continuous random variables,.pdf
Let X1, X2, . . . , Xn be n independent continuous random variables,.pdfLet X1, X2, . . . , Xn be n independent continuous random variables,.pdf
Let X1, X2, . . . , Xn be n independent continuous random variables,.pdfduttakajal70
 
In major league baseball, there are 5 teams in the Eastern division .pdf
In major league baseball, there are 5 teams in the Eastern division .pdfIn major league baseball, there are 5 teams in the Eastern division .pdf
In major league baseball, there are 5 teams in the Eastern division .pdfduttakajal70
 
Im off by a minus sign, can you find my error In a previous probl.pdf
Im off by a minus sign, can you find my error In a previous probl.pdfIm off by a minus sign, can you find my error In a previous probl.pdf
Im off by a minus sign, can you find my error In a previous probl.pdfduttakajal70
 
If the characteristic followed in the pedigree is X-linked recessiv.pdf
If the characteristic followed in the pedigree is X-linked recessiv.pdfIf the characteristic followed in the pedigree is X-linked recessiv.pdf
If the characteristic followed in the pedigree is X-linked recessiv.pdfduttakajal70
 
create a Tic Tac Toe game using JSP Scripting elements and a JSP pag.pdf
create a Tic Tac Toe game using JSP Scripting elements and a JSP pag.pdfcreate a Tic Tac Toe game using JSP Scripting elements and a JSP pag.pdf
create a Tic Tac Toe game using JSP Scripting elements and a JSP pag.pdfduttakajal70
 

More from duttakajal70 (20)

Explain the relevance of the rules against hearsay to digital eviden.pdf
Explain the relevance of the rules against hearsay to digital eviden.pdfExplain the relevance of the rules against hearsay to digital eviden.pdf
Explain the relevance of the rules against hearsay to digital eviden.pdf
 
Electric and magnetic fields in an electromagnetic wave are alway.pdf
Electric and magnetic fields in an electromagnetic wave are alway.pdfElectric and magnetic fields in an electromagnetic wave are alway.pdf
Electric and magnetic fields in an electromagnetic wave are alway.pdf
 
C# code pleaseWrite a program that creates a link list object of 1.pdf
C# code pleaseWrite a program that creates a link list object of 1.pdfC# code pleaseWrite a program that creates a link list object of 1.pdf
C# code pleaseWrite a program that creates a link list object of 1.pdf
 
During our laboratory exercise on cellular the Krebs cycle in.pdf
During our laboratory exercise on cellular the Krebs cycle in.pdfDuring our laboratory exercise on cellular the Krebs cycle in.pdf
During our laboratory exercise on cellular the Krebs cycle in.pdf
 
25. On January 3, Pippin Corporation purchased 1,900 shares of the c.pdf
25. On January 3, Pippin Corporation purchased 1,900 shares of the c.pdf25. On January 3, Pippin Corporation purchased 1,900 shares of the c.pdf
25. On January 3, Pippin Corporation purchased 1,900 shares of the c.pdf
 
Define filtration and active transport.SolutionFiltration is t.pdf
Define filtration and active transport.SolutionFiltration is t.pdfDefine filtration and active transport.SolutionFiltration is t.pdf
Define filtration and active transport.SolutionFiltration is t.pdf
 
Why wouldnt you want to post a payment against an invoice directly.pdf
Why wouldnt you want to post a payment against an invoice directly.pdfWhy wouldnt you want to post a payment against an invoice directly.pdf
Why wouldnt you want to post a payment against an invoice directly.pdf
 
Cisco routers and switches use two configuration files. Where is the.pdf
Cisco routers and switches use two configuration files. Where is the.pdfCisco routers and switches use two configuration files. Where is the.pdf
Cisco routers and switches use two configuration files. Where is the.pdf
 
Which of the following is a simple compressible system A mixtur.pdf
Which of the following is a simple compressible system  A mixtur.pdfWhich of the following is a simple compressible system  A mixtur.pdf
Which of the following is a simple compressible system A mixtur.pdf
 
Which of the following statements is (are) trueI Walls Street i.pdf
Which of the following statements is (are) trueI  Walls Street i.pdfWhich of the following statements is (are) trueI  Walls Street i.pdf
Which of the following statements is (are) trueI Walls Street i.pdf
 
What would be the most effective method of reducing the incidence of .pdf
What would be the most effective method of reducing the incidence of .pdfWhat would be the most effective method of reducing the incidence of .pdf
What would be the most effective method of reducing the incidence of .pdf
 
What is a micelle What is a vesicle How are these structures the s.pdf
What is a micelle What is a vesicle How are these structures the s.pdfWhat is a micelle What is a vesicle How are these structures the s.pdf
What is a micelle What is a vesicle How are these structures the s.pdf
 
To determine her breathing rate, Miranda divides up her day into thre.pdf
To determine her breathing rate, Miranda divides up her day into thre.pdfTo determine her breathing rate, Miranda divides up her day into thre.pdf
To determine her breathing rate, Miranda divides up her day into thre.pdf
 
On January 29th, 2014, the Royal Caribbean cruise ship Explorer of.pdf
On January 29th, 2014, the Royal Caribbean cruise ship Explorer of.pdfOn January 29th, 2014, the Royal Caribbean cruise ship Explorer of.pdf
On January 29th, 2014, the Royal Caribbean cruise ship Explorer of.pdf
 
Name and describe the six main types of lymphatic cells, discuss the.pdf
Name and describe the six main types of lymphatic cells, discuss the.pdfName and describe the six main types of lymphatic cells, discuss the.pdf
Name and describe the six main types of lymphatic cells, discuss the.pdf
 
Let X1, X2, . . . , Xn be n independent continuous random variables,.pdf
Let X1, X2, . . . , Xn be n independent continuous random variables,.pdfLet X1, X2, . . . , Xn be n independent continuous random variables,.pdf
Let X1, X2, . . . , Xn be n independent continuous random variables,.pdf
 
In major league baseball, there are 5 teams in the Eastern division .pdf
In major league baseball, there are 5 teams in the Eastern division .pdfIn major league baseball, there are 5 teams in the Eastern division .pdf
In major league baseball, there are 5 teams in the Eastern division .pdf
 
Im off by a minus sign, can you find my error In a previous probl.pdf
Im off by a minus sign, can you find my error In a previous probl.pdfIm off by a minus sign, can you find my error In a previous probl.pdf
Im off by a minus sign, can you find my error In a previous probl.pdf
 
If the characteristic followed in the pedigree is X-linked recessiv.pdf
If the characteristic followed in the pedigree is X-linked recessiv.pdfIf the characteristic followed in the pedigree is X-linked recessiv.pdf
If the characteristic followed in the pedigree is X-linked recessiv.pdf
 
create a Tic Tac Toe game using JSP Scripting elements and a JSP pag.pdf
create a Tic Tac Toe game using JSP Scripting elements and a JSP pag.pdfcreate a Tic Tac Toe game using JSP Scripting elements and a JSP pag.pdf
create a Tic Tac Toe game using JSP Scripting elements and a JSP pag.pdf
 

Recently uploaded

Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
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.pptxAreebaZafar22
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
Philosophy of china and it's charactistics
Philosophy of china and it's charactisticsPhilosophy of china and it's charactistics
Philosophy of china and it's charactisticshameyhk98
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxUmeshTimilsina1
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
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 POSCeline George
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 

Recently uploaded (20)

Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
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
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Philosophy of china and it's charactistics
Philosophy of china and it's charactisticsPhilosophy of china and it's charactistics
Philosophy of china and it's charactistics
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
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
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 

Java Program using RecursionWrite a program that reads in a file .pdf

  • 1. Java Program using Recursion: Write a program that reads in a file and outputs it to another file. The output file created should be identical to the input file but with its lines in reverse order. Use recursion. Obtain the names of the input and output files from the command line. For the input file, use a file that contains the integers 1 to 10, each on a seperate line. Solution I think the given code is working correctly import java.io.File; import java.io.FileInputStream; import java.io.InputStreamReader; import java.io.RandomAccessFile; import java.io.Reader; public class Reversefile { public static void main(String[] args) { FileInputStream fis = null; RandomAccessFile raf = null; String characterEncoding = "utf-8"; if(args.length==3) { characterEncoding = args[2]; } try{ File in = new File(args[0]); fis = new FileInputStream(in); Reader r = new InputStreamReader(fis,characterEncoding); File out = new File(args[1]); raf = new RandomAccessFile(out, "rw"); raf.setLength(in.length()); char[] buff = new char[1]; long position = in.length(); while((r.read(buff))>-1) { Character c = buff[0]; String s = c+""; byte[] bBuff = s.getBytes(characterEncoding);
  • 2. position = position-bBuff.length; raf.seek(position); raf.write(bBuff); } } catch (Exception e) { e.printStackTrace(); } finally { try { fis.close(); } catch (Exception e2) { } try { raf.close(); } catch (Exception e2) { } } } }