• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to make readOnly() file?  RSS feed

 
Vlad Stan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • 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?




 
Stephan van Hulst
Saloon Keeper
Posts: 7821
142
  • Mark post as helpful
  • send pies
  • 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
  • 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: 7821
142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What operating system are you working with?
 
Vlad Stan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • 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
 
Knute Snortum
Sheriff
Posts: 4091
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • 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: 7821
142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This works just fine for me:
 
Knute Snortum
Sheriff
Posts: 4091
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And this worked for me:
 
Vlad Stan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:Can you post the code that is trying to set the file to read only?



 
Carey Brown
Bartender
Posts: 3018
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • 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
Bartender
Posts: 3018
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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
Bartender
Posts: 3018
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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.

 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!