Can't move neither mp3 nor jpg with Files.move in java -
i finished reading question of same type unfortunaetly didn't me lot.
i have problem moving files mp3 , jpg folder created before trying move files.
here's code:
public class filessorter { private string extension; public filessorter(string ext) { this.setextension(ext); } public void setextension(string extension) { this.extension = extension; } public void sortit(path path, path filename) { string stringpath = path.tostring(); switch (this.extension) { case "folder": return; case "txt": file folderdocs = new file(stringpath + ("\\documents")); if (!folderdocs.exists()) { folderdocs.mkdir(); } path sourcedocs = path.resolve(filename); path targetdocs = folderdocs.topath().resolve(filename); try { files.move(sourcedocs, targetdocs, atomic_move); } catch (ioexception e) { system.out.println("moving failed."); } break; case "mp3": case "wma": case "ogg": file foldermsc = new file(stringpath + ("\\music")); if (!foldermsc.exists()) { system.out.println("created folder"); foldermsc.mkdir(); } path sourcemsc = path.resolve(filename); path targetmsc = foldermsc.topath().resolve(filename); system.out.println(sourcemsc); system.out.println(targetmsc); try { files.move(sourcemsc, targetmsc, replace_existing); } catch (ioexception e) { system.out.println("moving failed."); } break; ... }
and fragment i'm calling method:
while (true) { key = foldermonitor.take(); kind<?> tmp; (watchevent<?> eventsinfolder : key.pollevents()) { tmp = eventsinfolder.kind(); if (tmp == entry_create) { path recentlycreatedpath = ((watchevent<path>) eventsinfolder).context(); system.out.println("new path created: " + recentlycreatedpath); type = this.givemetype(string.valueof(recentlycreatedpath)); this.actwithfile(type, recentlycreatedpath); } else if (tmp == entry_delete) { system.out.println("path deleted: " + ((watchevent<path>) eventsinfolder).context()); } else if (tmp == overflow) { continue; } } if (!key.reset()) { break; } timethen = system.currenttimemillis(); if(timethen - timenow > 120000) { break; } }
as i've said, when try move txt works, when try move mp3 says "moving failed."
thank in advance answering question or giving other tips find such information.
edit: here's code call sortit method (sorry not making earlier).
private void actwithfile (string type, path pathtofile) { filessorter fs = new filessorter(type); fs.sortit(this.pathdirectory, pathtofile); }
Comments
Post a Comment