• 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

File Not storing: Java Filing program on Ubuntu 18.04, Netbeans 12.2 project

 
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Thanks Mark,

Following is my program related to filing



I am running the above program on Ubuntu 18.04 using Netbeans 12.2. My project name is: "fileWrite". It is a Mavern, Java Application project. It is not writing anything in the file abc.txt:


zulfi@lc2530hz:~$ cat abc.txt
zulfi@lc2530hz:~$ pwd
/home/zulfi
zulfi@lc2530hz:~$



I have also attached the project image.

Zulfi.

filewrite.png
[Thumbnail for filewrite.png]
 
Saloon Keeper
Posts: 7999
70
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is your error. You are passing in the result of getName() which is only "abc.txt", no path. You need to pass in "f1" without calling any of f1's methods.
 
Carey Brown
Saloon Keeper
Posts: 7999
70
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, look up try-with-resources, that will explain how to properly open and close a file.
 
Zulfi Khan
Ranch Hand
Posts: 178
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Your solution worked. The complete program is:



Thanks.

Zulfi.
 
Marshal
Posts: 3457
493
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
There is something that Carey mentioned that you may have missed - FileWriter also has a constructor which takes a File object as an argument, so you also could had alternatively created your FileWriter instance with:
    new FileWriter(f1,true)
 
Tick check! Okay, I guess that was just an itch. Oh wait! Just a tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic