?
Solved

Reading a filename from an Excel CSV file EASY 75PTS

Posted on 2005-05-12
7
Medium Priority
?
210 Views
Last Modified: 2010-03-31
i want the arg for filereader to be whatever the name of the file is in the specified directory so say for example the file is named "CRS April05 Writeoff.csv"
how would i code so that the app just picks up the file name instead of hardcoding it
into the application
thanks


 try {
                    BufferedReader in = new BufferedReader(new FileReader("yourFile.csv"));
                    String str;
                    while ((str = in.readLine()) != null) {
                          process(str);
                    }
                    in.close();
              } catch (IOException e) {
      
0
Comment
Question by:daveleblanc
7 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 13989398
String filename =  "CRS April05 Writeoff.csv";
...

BufferedReader in = new BufferedReader(new FileReader(filename));
0
 
LVL 13

Expert Comment

by:petmagdy
ID: 13989402
Hi daveleblanc,

u can use the file chooser dialog, as in this tutorial and sample:

http://java.sun.com/docs/books/tutorial/uiswing/components/filechooser.html

Cheers!
0
 

Author Comment

by:daveleblanc
ID: 13989432
CEHJ

file name cannot be hardcoded, i basically need it to any file placed in the directory

is this possible?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:daveleblanc
ID: 13989440
petmagdy thanks but that will not work as this application is handled via scheduling software, so there is no human interaction when the app is running
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 300 total points
ID: 13989463
FilenameFilter filter = new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.toLowerCase().endsWith(".csv");
        }
};
String[] fileNames = new File(directoryName).list(filter); // (where directoryName is your starting dir)
String csvFile = fileNames[0]; // range check it though
0
 
LVL 3

Expert Comment

by:cincin77
ID: 13989908
public void method(String arg){
String filename=arg+".csv";
BufferedReader in = new BufferedReader(new FileReader(filename));
}


do i miss something?
regards.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 13990385
:-)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month14 days, 13 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question