• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

How to make readOnly() file?

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can i make that file is read only and for example make it appear in desktop.
Cause i tried with readOnly(), and that didnt work for me.

Could you help me with my code please?




 
Saloon Keeper
Posts: 15730
368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Vlad, welcome to CodeRanch!

You should probably take a look at Files.setAttribute() to set an operating system specific attribute (such as "acl:acl", "posix:permissions" or "dos:readonly").

If that fails, take a look at File.setReadOnly().
 
Vlad Stan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:Hi Vlad, welcome to CodeRanch!

You should probably take a look at Files.setAttribute() to set an operating system specific attribute (such as "acl:acl", "posix:permissions" or "dos:readonly").

If that fails, take a look at File.setReadOnly().



well no idea , but i couldnt make it work,checked so much guides but....
readOnly was fine but when you open it still can write on it...
 
Stephan van Hulst
Saloon Keeper
Posts: 15730
368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What operating system are you working with?
 
Vlad Stan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:What operating system are you working with?


Win7 x64 Eclipse gui builder.
only thing that missing in my whole procjet... have been struggling few days already
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you post the code that is trying to set the file to read only?
 
Stephan van Hulst
Saloon Keeper
Posts: 15730
368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This works just fine for me:
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And this worked for me:
 
Vlad Stan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Knute Snortum wrote:Can you post the code that is trying to set the file to read only?




 
Saloon Keeper
Posts: 10930
87
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Call setReadOnly() after you write and close the file.
 
Vlad Stan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:Call setReadOnly() after you write and close the file.


Awsome did work now!

but how is it possible to get output:


my current output , but i want to get it -



 
Carey Brown
Saloon Keeper
Posts: 10930
87
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Vlad Stan wrote:but how is it possible to get output:

my current output , but i want to get it -


I don't see anything obviously wrong with your code. I'd need to know more about your table model. You seem to have more columns in your model than you want to write. Can you just write out the specific columns that you're interested in? You may have an issue with your newlines: \n vs \r\n, depending on which program you use to view the file.
 
Vlad Stan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:
I don't see anything obviously wrong with your code. I'd need to know more about your table model. You seem to have more columns in your model than you want to write. Can you just write out the specific columns that you're interested in? You may have an issue with your newlines: \n vs \r\n, depending on which program you use to view the file.




Well
this writes in first column the first name and lastname that user enters(on button click)


When he pushes test is done, it counts up correct answers and put them in second row.

Hope this helps .... cause i got around 1000+lines ^.^
 
Carey Brown
Saloon Keeper
Posts: 10930
87
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I put together this small program from your code. It works for me except that the format is off when I view it with Notepad, i.e. your "\n" would need to be "\r\n", as I said.

 
The harder you work, the luckier you get. This tiny ad brings luck - just not good luck or bad luck.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic