import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.Scanner;
import javax.swing.JFileChooser;
/**
* This class reads a user chosen file, reads its words
* reverses the order in which the words are stored in
* the file i.e. the last word becomes first and the first
* word becomes last.
* @author Dixit Bhatta
* **/
public class revFile {
public static void main(String[] args) throws IOException{
ArrayList<String> rev = new ArrayList<String>();//creating new ArrayList
String absolutePath = null; //to store path of the file
try {
File file = getInputFileNameFromUser();
//store the path of file to modify it later
absolutePath = file.getAbsolutePath();
Scanner filein = new Scanner(file); //open file
while(filein.hasNext()) {
String frame = filein.next();
rev.add(frame);// add the strings i.e. words to the ArrayList.
}//end of while
filein.close();//close the file
} catch (FileNotFoundException e) {//handle exception in case of error
System.err.println("FileNotFoundException: " + e.getMessage());
}
//display the number of words if it the file is not empty
if(!rev.isEmpty()){
int size = rev.size();
System.out.println("The number of words in file is: " + size);
}
Collections.reverse(rev);//reverse the arraylist
//use buffered writer and print writer to write into the file
BufferedWriter write = new BufferedWriter(new FileWriter(absolutePath));
PrintWriter out = new PrintWriter(write);
//writing the strings in the file using an iterator
Iterator<String> iter = rev.iterator();
while (iter.hasNext())
out.write(iter.next() + " ");
out.close();
}
/**
* Lets the user select an input file using a standard file
* selection dialog box. If the user cancels the dialog
* without selecting a file, the return value is null.
*/
static File getInputFileNameFromUser() {
JFileChooser fileDialog = new JFileChooser();
fileDialog.setDialogTitle("Select File for Input");
int option = fileDialog.showOpenDialog(null);
if (option != JFileChooser.APPROVE_OPTION)
return null;
else
return fileDialog.getSelectedFile();
}//end of choosing file
}
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.Scanner;
import javax.swing.JFileChooser;
/**
* This class reads a user chosen file, reads its words
* reverses the order in which the words are stored in
* the file i.e. the last word becomes first and the first
* word becomes last.
* @author Dixit Bhatta
* **/
public class revFile {
public static void main(String[] args) throws IOException{
ArrayList<String> rev = new ArrayList<String>();//creating new ArrayList
String absolutePath = null; //to store path of the file
try {
File file = getInputFileNameFromUser();
//store the path of file to modify it later
absolutePath = file.getAbsolutePath();
Scanner filein = new Scanner(file); //open file
while(filein.hasNext()) {
String frame = filein.next();
rev.add(frame);// add the strings i.e. words to the ArrayList.
}//end of while
filein.close();//close the file
} catch (FileNotFoundException e) {//handle exception in case of error
System.err.println("FileNotFoundException: " + e.getMessage());
}
//display the number of words if it the file is not empty
if(!rev.isEmpty()){
int size = rev.size();
System.out.println("The number of words in file is: " + size);
}
Collections.reverse(rev);//reverse the arraylist
//use buffered writer and print writer to write into the file
BufferedWriter write = new BufferedWriter(new FileWriter(absolutePath));
PrintWriter out = new PrintWriter(write);
//writing the strings in the file using an iterator
Iterator<String> iter = rev.iterator();
while (iter.hasNext())
out.write(iter.next() + " ");
out.close();
}
/**
* Lets the user select an input file using a standard file
* selection dialog box. If the user cancels the dialog
* without selecting a file, the return value is null.
*/
static File getInputFileNameFromUser() {
JFileChooser fileDialog = new JFileChooser();
fileDialog.setDialogTitle("Select File for Input");
int option = fileDialog.showOpenDialog(null);
if (option != JFileChooser.APPROVE_OPTION)
return null;
else
return fileDialog.getSelectedFile();
}//end of choosing file
}
©Dixit Bhatta 2013
ReplyDeleteThanks for the informative article. This is one of the best resources I have found in quite some time. Nicely written and great info. I really cannot thank you enough for sharing.
rpa training in bangalore
best rpa training in bangalore
RPA training in bangalore
rpa course in bangalore
rpa training in chennai
rpa online training
Whoa! I’m enjoying the template/theme of this website. It’s simple, yet effective. A lot of times it’s very hard to get that “perfect balance” between superb usability and visual appeal. I must say you’ve done a very good job with this.
ReplyDeleteAWS certification Training Online Bangalore
AWS Certification Training Online Pune
AWS certification Training Online Chennai
AWS Online Certification and Training
Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.
ReplyDeletepython Online training in chennai
python Online training in bangalore
python interview question and answers
Thanks For Sharing Your Information Please Keep UpDating Us The Information Shared Is Very Valuable Time Went On Just Reading The Article Python Online Training Devops Online Training
ReplyDeleteAws Online Training DataScience Online Training
Hadoop Online Training
There's no doubt that the future education will see a lot of advancements. One such example is AWS Training In Hyderabad from Kelly Technologies...
ReplyDeleteMore: https://www.kellytechno.com/Hyderabad/Course/amazon-web-services-training
This is most informative and provide useful article..I hope this information really helpful to all and also i share few link below
ReplyDeleteAndroid Training in Chennai
Android Online Training in Chennai
Android Training in Bangalore
Android Training in Hyderabad
Android Training in Coimbatore
Android Training
Android Online Training
Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article.
ReplyDelete360DigiTMG business analytics course
360DigiTMG best data science institute in hyderabad
360DigiTMG data analytics training
After reading your article I was amazed. I know that you explain it very well. And I hope that other readers will also experience how I feel after reading your article.
ReplyDelete360digiTMG.com artificial intelligence online course
Thanks for your post. This is excellent information. The list of your blogs is very helpful for those who want to learn, It is amazing!!! You have been helping many application.
ReplyDeleteSalesforce Training in Chennai
Salesforce Online Training in Chennai
Salesforce Training in Bangalore
Salesforce Training in Hyderabad
Salesforce training in ameerpet
Salesforce Training in Pune
Salesforce Online Training
Salesforce Training
PrimeVideo offers a variety of services, and this includes MyTV. There are many ways in which you can save money by watching TV on your computer instead of paying full price for cable. PrimeTV can help you save hundreds of dollars per year, and they offer many plans so you can find one that fits your lifestyle Visit www .primevideo.com mytv
ReplyDeleteif ur interested in learning AWS course please visit our website
ReplyDeleteAWS Training in Hyderabad
The AWS certification course has become the need of the hour for freshers, IT professionals, or young entrepreneurs. AWS is one of the largest global cloud platforms that aids in hosting and managing company services on the internet. It was conceived in the year 2006 to service the clients in the best way possible by offering customized IT infrastructure. Due to its robustness, Digital Nest added AWS training in Hyderabad under the umbrella of other courses.
ReplyDeleteReally awesome post, informative and knowledgeable content. Keep sharing more stuff with us. Thank you.
ReplyDeleteData Science Course Training in Hyderabad
Virtual event and extended reality (XR) tech were well represented at the trade show; the latter had a dedicated exhibition named XR Experience, the in-person sequel to the last edition’s SXSW Online XR. event technology Both technologies are likely propelled by the ramped-up investments in the metaverse and complementary technologies. how to write a debriefing report, event scheduling software, event swag bag, define experiential marketing, online registration site, presentation bio, how to have an online vendor event, thank you note for event and catchy invitation phrases
ReplyDeleteThanks for sharing this info about Best CA Academy in Hyderabad
ReplyDeleteBest CA Academy in Hyderabad
Thank You for Sharing Your Knowledge Please continue to update us Worth the time spent even just reading the article for the information shared.
ReplyDeleteBest Colleges For MEC In Hyderabad
Great post! As someone interested in cloud computing, Start a AWS journey.
ReplyDeleteNice Article!
ReplyDeleteThanks for sharing with us 🙂
Digital Marketing Course In Hyderabad