无法删除文件,但编写器已关闭
Cannot delete file but writers are closed
这是我写在文件中的代码..
FileOutputStream fos = new FileOutputStream( fileTAG, true );
OutputStreamWriter osw = new OutputStreamWriter( fos, strFileEncoding );
buf = new BufferedWriter( osw );
buf.write( strTagStream );
buf.newLine();
buf.flush();
if ( buf != null )
{
buf.close();
}
if ( osw != null )
{
osw.close();
}
if ( fos != null )
{
fos.close();
}
这是我的代码,先删除文件,然后删除目录:
File[] arrFiles = fileTagpath.listFiles();
for ( File fileCurrentFile : arrFiles )
{
if ( !fileCurrentFile.delete() )
{
String strMessage = "File <" + fileCurrentFile.getAbsolutePath() + "> has not been deleted.";
System.out.println( strMessage );
fail( strMessage );
}
}
if ( !fileTagpath.delete() )
{
String strMessage = "Directory <" + fileTagpath.getAbsolutePath() + "> has not been deleted.";
System.out.println( strMessage );
fail( strMessage );
}
失败并显示文件尚未删除的消息。输出显示正确的文件和正确的目录。如果我将路径复制到我的资源管理器 window,我会找到正确的文件。文件路径在
下
C:\Users\xxx\AppData\Local\Temp\tag
我的错误是什么?
在java中如果你想使用反斜杠。像这样尝试
你的路径:C:\Users\xxx\AppData\Local\Temp\tag
但是,您必须始终使用双反斜杠,如下所示:
C:\\Users\\xxx\\AppData\\Local\\Temp\\tag
这是我写在文件中的代码..
FileOutputStream fos = new FileOutputStream( fileTAG, true );
OutputStreamWriter osw = new OutputStreamWriter( fos, strFileEncoding );
buf = new BufferedWriter( osw );
buf.write( strTagStream );
buf.newLine();
buf.flush();
if ( buf != null )
{
buf.close();
}
if ( osw != null )
{
osw.close();
}
if ( fos != null )
{
fos.close();
}
这是我的代码,先删除文件,然后删除目录:
File[] arrFiles = fileTagpath.listFiles();
for ( File fileCurrentFile : arrFiles )
{
if ( !fileCurrentFile.delete() )
{
String strMessage = "File <" + fileCurrentFile.getAbsolutePath() + "> has not been deleted.";
System.out.println( strMessage );
fail( strMessage );
}
}
if ( !fileTagpath.delete() )
{
String strMessage = "Directory <" + fileTagpath.getAbsolutePath() + "> has not been deleted.";
System.out.println( strMessage );
fail( strMessage );
}
失败并显示文件尚未删除的消息。输出显示正确的文件和正确的目录。如果我将路径复制到我的资源管理器 window,我会找到正确的文件。文件路径在
下C:\Users\xxx\AppData\Local\Temp\tag
我的错误是什么?
在java中如果你想使用反斜杠。像这样尝试
你的路径:C:\Users\xxx\AppData\Local\Temp\tag
但是,您必须始终使用双反斜杠,如下所示:
C:\\Users\\xxx\\AppData\\Local\\Temp\\tag