java - Can't copy internal file to user's computer -
I have a program for which an internal file (DICTIONARY) can be copied to a folder copied to the user's computer :
Private Static Last String DICIDI = "WordHail DDIC"; Private Static Last String DIC_FOLDER = System.getProperty ("user.home"); Private static final string PATH_SEP = System.getProperty ("file.separator"); Public static final string DICTIONARY = DIC_FOLDER + PATH_SEP + DIC_NAME;
This works on my computer, where all Java content is:
public static zero createDictionaryIf required () throws IOException {path out_path = FileSystems. GetDefault () .getPath (dictionary); Boolean dic_exists = Files.exists (out_path, new link option [] (LinkOption.NOFOLLOW_LINKS}); if (dic_exists) return; file file = new file ("src / dictionary"); // Here is a problem for user *** Try ******** path in_path = file.toPath (); {Files.copy (in_path, out_path, REPLACE_EXISTING, COPY_ATTRIBUTES, NOFOLLOW_LINKS);} hold (IOException e) {JOptionPane.showMessageDialog (null, e But the user gets this error: java.nio.file.NoSuchFileException: src \ dictionary
The source file (internal to the .jar file) can not be found.
If I do debugging I see the in_path
, the value is:
(sun.nio.fs.Windowspath) src / dictionary
and Below is a bunch of information about in_path:
< / P>
All this works on my computer and I could swear that it works once on a user's computer.
How should I define file
(to enable the copy of the internal file ********************* ***************** (
"alt =" Enter image details here ">
/ P>
I use it with scanner
Files.copy
Instead of reading individual strings from the internal file. Here is the code (using this scanner
It is not fast, but it works.)
write public static zero (file output stream, output, string) {try {for (int i = 0; I & lt; S.length (); i ++) Outfile. Written (S.Artet (I)); outfile.write (13); outfile.write (10);} hold (IOException pre) {JOptionPane.showMessageDialog (empty, east );}} Public static scanner openDic () {InputStream mystream = null; try {mystream = Class.forName ("masterwords.Masterwords"). GetClassLoader () .getResourceAsStream ("Dictionary"); } Catch (KlassonThound Expression Pre) {/ * ... * /} New Scanner (Mystream) Reverse. Desalimeter ("\ r"); } Public static zero createDictionaryIf required () {path out_path = FileSystems.getDefault (). GetPath (DICTIONARY); If the files (.exis (out_path, new link option [] (link opus. NOFOLLOW_LINKS}) returns; FileOutputStream Outstream = Faucet; {Outstream = new FileOutputStream (out_path.toFile ())}} (pre-filenoutfound expression) {JOptionPane. ShowMessageDialog (null, ex);} scanner scInternalDic = IO.openDic (); while (scInternalDic.hasNext ()) {utilities. Written (outstream, scInternalDic.next ());} {outstream.close ();} hold ( IOException pre) {JOptionPane.showMessageDialog (tap, prior);} try scInternalDic.close ();}
Comments
Post a Comment