java


How to set the owner of a file from a string variable


FileOwnerAttributeView FOAttr = Files.getFileAttributeView(VidFile.toPath(),FileOwnerAttributeView.class);
System.out.println(FOAttr.getOwner());
UserPrincipalLookupService lookupService = FileSystems.getDefault().getUserPrincipalLookupService();
UserPrincipal FileOwner = lookupService.lookupPrincipalByName(UName);
System.out.println(FileOwner.getName());
FOAttr.setOwner(FileOwner);
What I think is a relatively simple question; I am trying to change the file's owner using the code given. It actually works pretty well up until I try to set the string variable UName to a UserPrincipal - I have included the proper import libraries but when I try to execute the code I get the following :
Exception in thread "main"
java.nio.file.attribute.UserPrincipalNotFoundException at
sun.nio.fs.WindowsUserPrincipals.lookup(WindowsUserPrincipals.java:147)
at
sun.nio.fs.WindowsFileSystem$LookupService$1.lookupPrincipalByName(WindowsFileSystem.java:270)
at
metadataretrieval.MetadataRetrieval.main(MetadataRetrieval.java:213)
C:\Users\rolsen\AppData\Local\NetBeans\Cache\8.1\executor-snippets\debug.xml:83:
Java returned: 1
and now I am a bit confused... is there a trick to setting the UserPrincipal to a specific user at runtime when that user's name is in a string variable?
import java.nio.file.Files;
import java.nio.file.FileSystems;
import java.nio.file.attribute.FileOwnerAttributeView;
import java.nio.file.attribute.UserPrincipalLookupService;
import java.nio.file.attribute.UserPrincipal;

Related Links

Java SWT Clipboard feature for Copy/Paste if not working for multiple items belonging to the same data type
remove all character without specefic char from string?
Is there a way to add query parameter to every request with Retrofit 2?
Not able to get getOutputStream() working in servlet
Google Drive API Android/Java - files list always empty
Reverse a comparator in Java 8
Merging 2 strings
How to do a final DB push when a Tomcat shutdown occurs?
Apache Commons Configuration : read a .properties file and rewrite it with no change
Hashmap returns null value when using a nested hashmap as the key
Selenium Automation on IE11 (Enterprise mode)
How to forbide to kill the app while writing to file continue
all possible paths for the robot [duplicate]
Trying to concatenate a series of strings via array
Eclipse maven plugin how to add jar?
how to change this query in Hibernate? comma separated list in one column

Categories

HOME
pdf
openlayers
amazon-ec2
c#-4.0
iterator
vmware
grep
bpmn
jsp-tags
sharepoint-designer
pivotal-cloud-foundry
slick-slider
communication
metatrader4
fancybox-3
dax
floating-action-button
modelica
php-7.1
visual-studio-cordova
tostring
transformation
evopdf
openedx
karma-jasmine
alpine
swiftlint
jndi
dynamic-featured-image
bootstrap-duallistbox
fifo
jaxb2
instant-messaging
fabric8
exuberant-ctags
android-kernel
serve
web-mining
trim
particles.js
galen
http-live-streaming
acoustics
qcombobox
babel-core
qwt
rainbowtable
youcompleteme
multipeer-connectivity
jlink
lowpass-filter
setter
jxcore
typed-lambda-calculus
android-cursor
pdfclown
background-service
url-pattern
grails-tomcat-plugin
android-textview
phishing
bluegiga
cloudbees
energy
wireshark-dissector
generic-programming
web-controls
directoryservices
gwidgets
java.util.concurrent
codeigniter-routing
castle
funcunit
valueconverter
gnu-smalltalk
pyhdf
multiprocessor
runtime.exec
odata4j
padarn
random-seed
clipper
hamiltonian-cycle
manchester-syntax
regsvr32
nsmanagedobject
libc++
deobfuscation
xdomainrequest
.nettiers
firefox4
sector
scripting-languages

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App