当 运行 应用程序作为 exe 时,无法将 TIFF 以外的图像移动到另一个文件夹
Cannot move images other than TIFF to another folder when running application as exe
我正在制作一个将图像从一个文件夹移动到另一个文件夹的应用程序,但是当我尝试移动扩展名为非 TIFF 的文件时出现错误。重要的是,当我通过 Eclipse 或 JAR 运行 这个程序时,它可以正常工作并移动任何具有任何扩展名的图像,但作为 EXE,它会出错。示例代码如下:
public class MovingFilesExample {
public static ArrayList<File> oDesiredFiles = new ArrayList<File>();
public static String[] oFileNameStarts;
public static File oInputFile = new File("D:/For_Sonal/NewOutput/456214538741259_LAND.BMP"), oDestDir = new File("D:/FILECONVERSIONS/OUTPUT/");
public static String strDesiredName;
public static Path oSourcePath, oDestPath;
public static PrintStream ps;
public static void main(String[] args) {
// TODO Auto-generated method stub
try
{
File file = new File("Exception.log");
ps = new PrintStream(file);
if(oDestDir.mkdirs())
{
System.out.println("Directories made !!!");
System.out.println();
}
else
{
System.out.println("Directories not made !!!");
System.out.println();
}
File oOutputFile = new File(oDestDir.getAbsolutePath() + "/" + oInputFile_1.getName());
oDestPath = oOutputFile.toPath();
System.out.println("Destination Path : " + oOutputFile.toPath());
oSourcePath = oInputFile_1.toPath();
if(new File(oSourcePath.toString()).exists())
{
//Files.copy(oSourcePath, oDestPath, StandardCopyOption.REPLACE_EXISTING);
Files.move(oSourcePath, oDestPath, StandardCopyOption.REPLACE_EXISTING);
}
}
catch(Exception e)
{
e.printStackTrace();
e.printStackTrace(ps);
}
ps.close();
}
我在
得到"java.nio.file.AccessDeniedException: D:\For_Sonal\NewOutput6214538741259_LAND.BMP -> D:\FILECONVERSIONS\OUTPUT6214538741259_LAND.BMP"
Files.move(oSourcePath, oDestPath, StandardCopyOption.REPLACE_EXISTING);
我还在应用程序路径中创建一个日志文件 "Exception.log",以便我们可以查看发生的异常。所以谁能告诉我这背后的原因是什么。
与Java无关。这是简单的 OS(在本例中为 Windows)安全设置。
仔细检查您 运行 您的 exe 的 ID。它是像 IIS 这样的服务或应用程序吗?通常他们有一些设置来标识要使用的 ID。
理解它的简单方法 - 运行 您的 Java 应用程序中的另一个进程,在此进程中 运行 命令 WhoAmI。
我正在制作一个将图像从一个文件夹移动到另一个文件夹的应用程序,但是当我尝试移动扩展名为非 TIFF 的文件时出现错误。重要的是,当我通过 Eclipse 或 JAR 运行 这个程序时,它可以正常工作并移动任何具有任何扩展名的图像,但作为 EXE,它会出错。示例代码如下:
public class MovingFilesExample {
public static ArrayList<File> oDesiredFiles = new ArrayList<File>();
public static String[] oFileNameStarts;
public static File oInputFile = new File("D:/For_Sonal/NewOutput/456214538741259_LAND.BMP"), oDestDir = new File("D:/FILECONVERSIONS/OUTPUT/");
public static String strDesiredName;
public static Path oSourcePath, oDestPath;
public static PrintStream ps;
public static void main(String[] args) {
// TODO Auto-generated method stub
try
{
File file = new File("Exception.log");
ps = new PrintStream(file);
if(oDestDir.mkdirs())
{
System.out.println("Directories made !!!");
System.out.println();
}
else
{
System.out.println("Directories not made !!!");
System.out.println();
}
File oOutputFile = new File(oDestDir.getAbsolutePath() + "/" + oInputFile_1.getName());
oDestPath = oOutputFile.toPath();
System.out.println("Destination Path : " + oOutputFile.toPath());
oSourcePath = oInputFile_1.toPath();
if(new File(oSourcePath.toString()).exists())
{
//Files.copy(oSourcePath, oDestPath, StandardCopyOption.REPLACE_EXISTING);
Files.move(oSourcePath, oDestPath, StandardCopyOption.REPLACE_EXISTING);
}
}
catch(Exception e)
{
e.printStackTrace();
e.printStackTrace(ps);
}
ps.close();
}
我在
得到"java.nio.file.AccessDeniedException: D:\For_Sonal\NewOutput6214538741259_LAND.BMP -> D:\FILECONVERSIONS\OUTPUT6214538741259_LAND.BMP"Files.move(oSourcePath, oDestPath, StandardCopyOption.REPLACE_EXISTING);
我还在应用程序路径中创建一个日志文件 "Exception.log",以便我们可以查看发生的异常。所以谁能告诉我这背后的原因是什么。
与Java无关。这是简单的 OS(在本例中为 Windows)安全设置。 仔细检查您 运行 您的 exe 的 ID。它是像 IIS 这样的服务或应用程序吗?通常他们有一些设置来标识要使用的 ID。
理解它的简单方法 - 运行 您的 Java 应用程序中的另一个进程,在此进程中 运行 命令 WhoAmI。