2 Replies - 13668 Views - Last Post: 05 April 2009 - 02:52 PM Rate Topic: -----

#1 doha786  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 63
  • Joined: 26-March 09

how to get file name or file path ?

Post icon  Posted 05 April 2009 - 01:21 PM

i need a small help to get file name or full path for output files of my program. so far my program is running as a search engine to find all of my friends name from many files and compare the similarity with a constructor "LCS".

the part of my code:
FileReader reader; BufferedReader br;
String result=""; String word= new String();
String target = "friend";
ArrayList names = new ArrayList();

try{ //read many files from folder
File directory = new File("C:/Users/Test");

File file[]= directory.listFiles();

for (File allFiles: file) {

reader = new FileReader (allFiles);
br = new BufferedReader(reader);
Scanner scan = new Scanner(reader); 

while(scan.hasNext()){ scan.next();
result = scan.findWithinHorizon(target,0); 

if(result!=null) {
word = (scan.next() + scan.findWithinHorizon("", 0));

names.add(word)
for (String found: names){ } 

}

}
scan.close();
br.close();
}
Scanner scanner = new Scanner(System.in);
String searchName;
System.out.print("Enter name to Search : ");
searchName = scanner.next();

for (String found: names) {

double compare = ReadFilesAndCompare.LCS(found, searchName);
//if (compare >= 50.0) {
System.out.println("Found names : "+found+ "\t" +"Similarity score: " +compare); }
FileReader reader; BufferedReader br;
String result=""; String word= new String();
String target = "friend";
ArrayList names = new ArrayList();

try{ //read many files from folder
File directory = new File("C:/Users/Test");

File file[]= directory.listFiles();

for (File allFiles: file) {

reader = new FileReader (allFiles);
br = new BufferedReader(reader);
Scanner scan = new Scanner(reader); 

while(scan.hasNext()){ scan.next();
result = scan.findWithinHorizon(target,0); 

if(result!=null) {
word = (scan.next() + scan.findWithinHorizon("", 0));

names.add(word)
for (String found: names){ } 

}

}
scan.close();
br.close();
}
Scanner scanner = new Scanner(System.in);
String searchName;
System.out.print("Enter name to Search : ");
searchName = scanner.next();

for (String found: names) {

double compare = ReadFilesAndCompare.LCS(found, searchName);
//if (compare >= 50.0) {
System.out.println("Found names : "+found+ "\t" +"Similarity score: " +compare); }




what should i use here to getFile name for my found result ??

Can anybody please give a easiest solution for me ?


my ouput is like this :

Quote

Enter name to Search : jack

Found names : vijoy Similarity score: 13.0
Found names : jacky Similarity score: 89.3733444
Found names : jedabe Similarity score: 29.43011


Is This A Good Question/Topic? 0
  • +

Replies To: how to get file name or file path ?

#2 Fuzzyness  Icon User is offline

  • Comp Sci Student
  • member icon

Reputation: 669
  • View blog
  • Posts: 2,438
  • Joined: 06-March 09

Re: how to get file name or file path ?

Posted 05 April 2009 - 01:37 PM

JFileChooser chooser = new JFileChooser();
   		File infile = null;
   		FileReader reader = null;
   		if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION)
   		{
   			infile = chooser.getSelectedFile();
   			reader = new FileReader(infile);
   		}
		Scanner input = new Scanner(infile);


Hope this helps!
Was This Post Helpful? 1
  • +
  • -

#3 doha786  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 63
  • Joined: 26-March 09

Re: how to get file name or file path ?

Posted 05 April 2009 - 02:52 PM

thanks for ur reply.....

but actually this is a small search engine so if user know where is the file then how come ??

i want to get output like this:

Found name: ........ similarity score: ..... File name : ........

right now just need to get path or get fileName for the found names.. but i cant make it.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1