• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

FileNotFound Exception when writing to text file - NetBeans 8 on Windows

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I am trying to write data to a text file on my Desktop using PrintWriter in Java, but the file is not appearing and it is throwing a FileNotFound Exception. However it works fine in a Mac environment when compiled and ran in the same fashion. At first, I thought it was because the file systems are different, so I gave it an absolute file path in the form of C:/Users/[username]/Desktop/[filename].txt but it still doesn't work. Here is the method I am writing:



Thank you in advance,
Ramon
 
Sheriff
Posts: 3913
542
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Trying printing the value of pathFileName to the console to see what it looks like.  I'm guessing that theTime.getTimeStamp() returns something that contains characters which are not valid for a Windows file name such colon characters used for hours:minutes:seconds .
 
Ron McLeod
Sheriff
Posts: 3913
542
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For example:
 
Ramon Santos
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for the reply. That makes sense because I was trying to write to another file that did not have a timestamp in the name and it worked. Is there a way to add a timestamp in another form?

Thanks,
Ramon
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can define your own format using a DateTimeFormatter.
 
The world's cheapest jedi mind trick: "Aw c'mon, why not read this tiny ad?"
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic