Win a copy of Pipeline as Code this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

Path problems

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all!

Im preparing the OCP certification exam and i made this piece of code just to check how it works some of the elements i have to study.



When i execute the code it prints me the following names of the files i have in the path:

C:\Users\Javier\workspace\OCP_3_2_Paths
C:\Users\Javier\workspace\OCP_3_2_Paths
C:\
.classpath
.project
org.eclipse.jdt.core.prefs
File01.txt
File02
CreatingPaths.class
FileOCP01.txt
FileOCP02
Visitor.class
Eliminar.txt
Paths.txt
File01.txt
File02
CreatingPaths.java
FileOCP01.txt
FileOCP02
Visitor.java
temp



The problem is that the code should delete me the files what end in ".txt" but actually it doesnt do anything. When i reach with "File01.txt", for example, the if returns me a FALSE.

Can you help me, please? thank you in advance!
 
Ranch Hand
Posts: 385
6
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
getFileName() returns a Path object, and not a String.

endsWith() works differently on a Path and String.

What you need to do is change the Path to a String and then call endsWith().

So your code should look like:

 
Javier Giron
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok, got it!! Thank you very much!!
 
I got this tall by not having enough crisco in my diet as a kid. This ad looks like it had plenty of shortening:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic