FileUtils方法大全(1)

2024-04-24 22:18
文章标签 方法 大全 fileutils

本文主要是介绍FileUtils方法大全(1),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

FileUtils

获取系统的临时目录路径:getTempDirectoryPath()

publicstatic String getTempDirectoryPath() {

           returnSystem.getProperty("java.io.tmpdir");

     }

获取代表系统临时目录的文件:getTempDirectory ()

publicstatic File getTempDirectory() {

           return newFile(getTempDirectoryPath());

       }

获取用户的主目录路径:getUserDirectoryPath()

publicstatic String getUserDirectoryPath() {

           returnSystem.getProperty("user.home");

       }

获取代表用户主目录的文件:getUserDirectory()

publicstatic File getUserDirectory() {

           return newFile(getUserDirectoryPath());

       }

根据指定的文件获取一个新的文件输入流:openInputStream(File file)

publicstatic FileInputStream openInputStream(File file) throws IOException {

           if (file.exists()) {

               if (file.isDirectory()) {

                   throw newIOException("File '" + file + "' exists but is adirectory");

               }

               if (file.canRead() == false) {

                   throw newIOException("File '" + file + "' cannot be read");

               }

           } else {

               throw newFileNotFoundException("File '" + file + "' does notexist");

           }

           return new FileInputStream(file);

       }

根据指定的文件获取一个新的文件输出流:openOutputStream (File file)

publicstatic FileOutputStream openOutputStream(File file) throws IOException {

           if (file.exists()) {

               if (file.isDirectory()) {

                   throw new IOException("File'" + file + "' exists but is a directory");

               }

               if (file.canWrite() == false) {

                   throw newIOException("File '" + file + "' cannot be written to");

               }

           } else {

               File parent = file.getParentFile();

               if (parent != null &&parent.exists() == false) {

                   if (parent.mkdirs() ==false) {

                       throw newIOException("File '" + file + "' could not be created");

                   }

               }

           }

           return new FileOutputStream(file);

       }

字节转换成直观带单位的值(包括单位GB,MB,KB或字节)byteCountToDisplaySize(long size)

  public static StringbyteCountToDisplaySize(long size) {

           String displaySize;

  

           if (size / ONE_GB > 0) {

               displaySize =String.valueOf(size / ONE_GB) + " GB";

           } else if (size / ONE_MB > 0) {

               displaySize =String.valueOf(size / ONE_MB) + " MB";

           } else if (size / ONE_KB > 0) {

               displaySize =String.valueOf(size / ONE_KB) + " KB";

           } else {

               displaySize =String.valueOf(size) + " bytes";

           }

           return displaySize;

       }

创建一个空文件,若文件应经存在则只更改文件的最近修改时间:touch(File file)

  public static void touch(File file) throwsIOException {

           if (!file.exists()) {

               OutputStream out =openOutputStream(file);

               IOUtils.closeQuietly(out);

           }

           boolean success =file.setLastModified(System.currentTimeMillis());

           if (!success) {

               throw new IOException("Unableto set the last modification time for " + file);

           }

       }

把相应的文件集合转换成文件数组convertFileCollectionToFileArray(Collection<File> files)

publicstatic File[] convertFileCollectionToFileArray(Collection<File> files) {

            return files.toArray(newFile[files.size()]);

       }

根据一个过滤规则获取一个目录下的文件innerListFiles(Collection<File> files, File directory,IOFileFilterfilter)

privatestatic void innerListFiles(Collection<File> files, File directory,

               IOFileFilter filter) {

           File[] found =directory.listFiles((FileFilter) filter);

           if (found != null) {

               for (File file : found) {

                   if (file.isDirectory()) {

                       innerListFiles(files,file, filter);

                   } else {

                       files.add(file);

                   }

               }

           }

       }

根据一个IOFileFilter过滤规则获取一个目录下的文件集合listFiles(

               File directory, IOFileFilterfileFilter, IOFileFilter dirFilter)

publicstatic Collection<File> listFiles(

               File directory, IOFileFilterfileFilter, IOFileFilter dirFilter) {

           if (!directory.isDirectory()) {

               throw newIllegalArgumentException(

                       "Parameter'directory' is not a directory");

           }

           if (fileFilter == null) {

               throw newNullPointerException("Parameter 'fileFilter' is null");

           }

  

           //Setup effective file filter

           IOFileFilter effFileFilter =FileFilterUtils.and(fileFilter,

               FileFilterUtils.notFileFilter(DirectoryFileFilter.INSTANCE));

  

           //Setup effective directory filter

           IOFileFilter effDirFilter;

           if (dirFilter == null) {

               effDirFilter =FalseFileFilter.INSTANCE;

           } else {

               effDirFilter =FileFilterUtils.and(dirFilter,

                  DirectoryFileFilter.INSTANCE);

           }

  

           //Find files

           Collection<File> files = newjava.util.LinkedList<File>();

           innerListFiles(files, directory,

              FileFilterUtils.or(effFileFilter, effDirFilter));

           return files;

       }

根据一个IOFileFilter过滤规则获取一个目录下的文件集合的Iterator迭代器iterateFiles(

               File directory, IOFileFilterfileFilter, IOFileFilter dirFilter)

     public static Iterator<File>iterateFiles(

               File directory, IOFileFilterfileFilter, IOFileFilter dirFilter) {

           return listFiles(directory,fileFilter, dirFilter).iterator();

       }

把指定的字符串数组变成后缀名格式字符串数组toSuffixes(String[] extensions)

privatestatic String[] toSuffixes(String[] extensions) {

           String[] suffixes = newString[extensions.length];

           for (int i = 0; i <extensions.length; i++) {

               suffixes[i] = "." +extensions[i];

           }

           return suffixes;

       }

查找一个目录下面符合对应扩展名的文件的集合listFiles(

               File directory, String[]extensions, boolean recursive)

 public static Collection<File>listFiles(

               File directory, String[]extensions, boolean recursive) {

           IOFileFilter filter;

           if (extensions == null) {

               filter =TrueFileFilter.INSTANCE;

           } else {

               String[] suffixes =toSuffixes(extensions);

               filter = newSuffixFileFilter(suffixes);

           }

           return listFiles(directory, filter,

               (recursive ?TrueFileFilter.INSTANCE : FalseFileFilter.INSTANCE));

       }

查找一个目录下面符合对应扩展名的文件的集合的迭代器Iterator<File> iterateFiles(

               File directory, String[]extensions, boolean recursive)

publicstatic Iterator<File> iterateFiles(

               File directory, String[]extensions, boolean recursive) {

           return listFiles(directory,extensions, recursive).iterator();

       }

判断两个文件是否相等contentEquals(Filefile1, File file2)

publicstatic boolean contentEquals(File file1, File file2) throws IOException {

           boolean file1Exists =file1.exists();

           if (file1Exists != file2.exists()) {

               return false;

           }

  

           if (!file1Exists) {

               // two not existing files areequal

               return true;

           }

  

           if (file1.isDirectory() ||file2.isDirectory()) {

               // don't want to comparedirectory contents

               throw newIOException("Can't compare directories, only files");

           }

  

           if (file1.length() !=file2.length()) {

               // lengths differ, cannot beequal

               return false;

           }

  

           if(file1.getCanonicalFile().equals(file2.getCanonicalFile())) {

               // same file

               return true;

           }

  

           InputStream input1 = null;

           InputStream input2 = null;

           try {

               input1 = newFileInputStream(file1);

               input2 = newFileInputStream(file2);

               returnIOUtils.contentEquals(input1, input2);

  

           } finally {

               IOUtils.closeQuietly(input1);

               IOUtils.closeQuietly(input2);

           }

       }

根据一个Url来创建一个文件toFile(URL url)

publicstatic File toFile(URL url) {

           if (url == null ||!"file".equalsIgnoreCase(url.getProtocol())) {

               return null;

           } else {

               String filename =url.getFile().replace('/', File.separatorChar);

               filename = decodeUrl(filename);

               return new File(filename);

           }

       }

 

对一个Url字符串进行将指定的URL按照RFC 3986进行转换decodeUrl(Stringurl)

staticString decodeUrl(String url) {

           String decoded = url;

           if (url != null &&url.indexOf('%') >= 0) {

               int n = url.length();

               StringBuffer buffer = newStringBuffer();

               ByteBuffer bytes =ByteBuffer.allocate(n);

               for (int i = 0; i < n;) {

                   if (url.charAt(i) == '%') {

                       try {

                           do {

                               byte octet =(byte) Integer.parseInt(url.substring(i + 1, i + 3), 16);

                              bytes.put(octet);

                               i += 3;

                           } while (i < n&& url.charAt(i) == '%');

                           continue;

                       } catch(RuntimeException e) {

                           // malformedpercent-encoded octet, fall through and

                           // append charactersliterally

                       } finally {

                           if (bytes.position()> 0) {

                               bytes.flip();

                              buffer.append(UTF8.decode(bytes).toString());

                               bytes.clear();

                           }

                       }

                   }

                  buffer.append(url.charAt(i++));

               }

               decoded = buffer.toString();

           }

           return decoded;

       }

将一个URL数组转化成一个文件数组toFiles(URL[] urls)

publicstatic File[] toFiles(URL[] urls) {

           if (urls == null || urls.length ==0) {

               return EMPTY_FILE_ARRAY;

           }

           File[] files = newFile[urls.length];

           for (int i = 0; i < urls.length;i++) {

               URL url = urls[i];

               if (url != null) {

                   if(url.getProtocol().equals("file") == false) {

                       throw newIllegalArgumentException(

                               "URL couldnot be converted to a File: " + url);

                   }

                   files[i] = toFile(url);

               }

           }

           return files;

       }

将一个文件数组转化成一个URL数组toURLs(File[] files)

   public static URL[] toURLs(File[] files)throws IOException {

           URL[] urls = new URL[files.length];

  

           for (int i = 0; i < urls.length;i++) {

               urls[i] =files[i].toURI().toURL();

           }

  

           return urls;

       }

拷贝一个文件到指定的目录文件copyFileToDirectory(File srcFile, File destDir)

publicstatic void copyFileToDirectory(File srcFile, File destDir) throws IOException{

           copyFileToDirectory(srcFile,destDir, true);

       }

拷贝一个文件到指定的目录文件并且设置是否更新文件的最近修改时间copyFileToDirectory(File srcFile, File destDir, booleanpreserveFileDate)

publicstatic void copyFileToDirectory(File srcFile, File destDir, booleanpreserveFileDate) throws IOException {

           if (destDir == null) {

               throw newNullPointerException("Destination must not be null");

           }

           if (destDir.exists() &&destDir.isDirectory() == false) {

               throw newIllegalArgumentException("Destination '" + destDir + "' is not adirectory");

           }

           File destFile = new File(destDir,srcFile.getName());

           copyFile(srcFile, destFile,preserveFileDate);

       }

拷贝文件到新的文件中并且保存最近修改时间copyFile(File srcFile, File destFile)

publicstatic void copyFile(File srcFile, File destFile) throws IOException {

           copyFile(srcFile, destFile, true);

       }

拷贝文件到新的文件中并且设置是否保存最近修改时间copyFile(File srcFile, File destFile,

               boolean preserveFileDate)

publicstatic void copyFile(File srcFile, File destFile,

               boolean preserveFileDate) throwsIOException {

           if (srcFile == null) {

               throw newNullPointerException("Source must not be null");

           }

           if (destFile == null) {

               throw newNullPointerException("Destination must not be null");

           }

           if (srcFile.exists() == false) {

               throw newFileNotFoundException("Source '" + srcFile + "' does notexist");

           }

           if (srcFile.isDirectory()) {

               throw newIOException("Source '" + srcFile + "' exists but is adirectory");

           }

           if(srcFile.getCanonicalPath().equals(destFile.getCanonicalPath())) {

               throw newIOException("Source '" + srcFile + "' and destination '" +destFile + "' are the same");

           }

           if (destFile.getParentFile() != null&& destFile.getParentFile().exists() == false) {

               if(destFile.getParentFile().mkdirs() == false) {

                   throw newIOException("Destination '" + destFile + "' directory cannot becreated");

               }

           }

           if (destFile.exists() &&destFile.canWrite() == false) {

               throw newIOException("Destination '" + destFile + "' exists but isread-only");

           }

           doCopyFile(srcFile, destFile,preserveFileDate);

       }

拷贝文件到新的文件中并且设置是否保存最近修改时间doCopyFile(File srcFile, File destFile, boolean preserveFileDate)

  private static void doCopyFile(File srcFile,File destFile, boolean preserveFileDate) throws IOException {

           if (destFile.exists() &&destFile.isDirectory()) {

               throw newIOException("Destination '" + destFile + "' exists but is adirectory");

           }

  

           FileInputStream fis = null;

           FileOutputStream fos = null;

           FileChannel input = null;

           FileChannel output = null;

           try {

               fis = newFileInputStream(srcFile);

               fos = newFileOutputStream(destFile);

               input  = fis.getChannel();

               output = fos.getChannel();

               long size = input.size();

               long pos = 0;

               long count = 0;

               while (pos < size) {

                   count = (size - pos) >FIFTY_MB ? FIFTY_MB : (size - pos);

                   pos +=output.transferFrom(input, pos, count);

               }

           } finally {

               IOUtils.closeQuietly(output);

               IOUtils.closeQuietly(fos);

               IOUtils.closeQuietly(input);

               IOUtils.closeQuietly(fis);

           }

  

           if (srcFile.length() !=destFile.length()) {

               throw newIOException("Failed to copy full contents from '" +

                       srcFile + "' to '"+ destFile + "'");

           }

           if (preserveFileDate) {

              destFile.setLastModified(srcFile.lastModified());

           }

       }

将一个目录拷贝到另一目录中,并且保存最近更新时间copyDirectoryToDirectory(File srcDir, File destDir)

publicstatic void copyDirectoryToDirectory(File srcDir, File destDir) throwsIOException {

           if (srcDir == null) {

               throw newNullPointerException("Source must not be null");

           }

           if (srcDir.exists() &&srcDir.isDirectory() == false) {

               throw new IllegalArgumentException("Source'" + destDir + "' is not a directory");

           }

           if (destDir == null) {

               throw newNullPointerException("Destination must not be null");

           }

           if (destDir.exists() &&destDir.isDirectory() == false) {

               throw newIllegalArgumentException("Destination '" + destDir + "' is not adirectory");

           }

           copyDirectory(srcDir, newFile(destDir, srcDir.getName()), true);

       }

拷贝整个目录到新的位置,并且保存最近修改时间copyDirectory(File srcDir, File destDir)

  publicstatic void copyDirectory(File srcDir, File destDir) throws IOException{

           copyDirectory(srcDir, destDir,true);

       }

拷贝整个目录到新的位置,并且设置是否保存最近修改时间copyDirectory(File srcDir, File destDir, boolean preserveFileDate)

publicstatic void copyDirectory(File srcDir, File destDir,

               boolean preserveFileDate) throwsIOException {

           copyDirectory(srcDir, destDir, null,preserveFileDate);

       }

拷贝过滤后的目录到指定的位置,并且保存最近修改时间copyDirectory(File srcDir, File destDir, FileFilter filter)

publicstatic void copyDirectory(File srcDir, File destDir,

               FileFilter filter) throwsIOException {

           copyDirectory(srcDir, destDir,filter, true);

       }

拷贝过滤后的目录到指定的位置,并且设置是否保存最近修改时间copyDirectory(File srcDir, File destDir,FileFilter filter, booleanpreserveFileDate)

publicstatic void copyDirectory(File srcDir, File destDir,

                FileFilter filter, booleanpreserveFileDate) throws IOException {

            if (srcDir == null) {

                throw newNullPointerException("Source must not be null");

            }

            if (destDir == null) {

                throw newNullPointerException("Destination must not be null");

            }

            if (srcDir.exists() == false) {

                throw newFileNotFoundException("Source '" + srcDir + "' does notexist");

            }

            if (srcDir.isDirectory() == false){

                throw newIOException("Source '" + srcDir + "' exists but is not adirectory");

            }

            if(srcDir.getCanonicalPath().equals(destDir.getCanonicalPath())) {

                throw newIOException("Source '" + srcDir + "' and destination '" +destDir + "' are the same");

            }

   

            // Cater for destination being directorywithin the source directory (see IO-141)

            List<String> exclusionList =null;

            if(destDir.getCanonicalPath().startsWith(srcDir.getCanonicalPath())) {

                File[] srcFiles = filter ==null ? srcDir.listFiles() : srcDir.listFiles(filter);

                if (srcFiles != null &&srcFiles.length > 0) {

                    exclusionList = newArrayList<String>(srcFiles.length);

                    for (File srcFile :srcFiles) {

                        File copiedFile = newFile(destDir, srcFile.getName());

                       exclusionList.add(copiedFile.getCanonicalPath());

                    }

                }

            }

            doCopyDirectory(srcDir, destDir,filter, preserveFileDate, exclusionList);

        }

内部拷贝目录的方法doCopyDirectory(FilesrcDir, File destDir, FileFilter filter,

                boolean preserveFileDate,List<String> exclusionList)

privatestatic void doCopyDirectory(File srcDir, File destDir, FileFilter filter,

                boolean preserveFileDate,List<String> exclusionList) throws IOException {

            // recurse

            File[] files = filter == null ?srcDir.listFiles() : srcDir.listFiles(filter);

            if (files == null) {  // null if security restricted

                throw newIOException("Failed to list contents of " + srcDir);

            }

            if (destDir.exists()) {

                if (destDir.isDirectory() ==false) {

                    throw newIOException("Destination '" + destDir + "' exists but is not adirectory");

                }

            } else {

                if (destDir.mkdirs() == false){

                    throw newIOException("Destination '" + destDir + "' directory cannot becreated");

                }

            }

            if (destDir.canWrite() == false) {

                throw newIOException("Destination '" + destDir + "' cannot be writtento");

            }

            for (File file : files) {

                File copiedFile = newFile(destDir, file.getName());

                if (exclusionList == null ||!exclusionList.contains(file.getCanonicalPath())) {

                    if (file.isDirectory()) {

                        doCopyDirectory(file,copiedFile, filter, preserveFileDate, exclusionList);

                    } else {

                        doCopyFile(file,copiedFile, preserveFileDate);

                    }

                }

            }

   

            // Do this last, as the above hasprobably affected directory metadata

            if (preserveFileDate) {

               destDir.setLastModified(srcDir.lastModified());

            }

        }

根据一个Url拷贝字节到一个文件中copyURLToFile(URL source, File destination)

publicstatic void copyURLToFile(URL source, File destination) throws IOException {

            InputStream input =source.openStream();

            copyInputStreamToFile(input,destination);

        }

根据一个Url拷贝字节到一个文件中,并且可以设置连接的超时时间和读取的超时时间

copyURLToFile(URLsource, File destination,

                int connectionTimeout, int readTimeout)

publicstatic void copyURLToFile(URL source, File destination,

                int connectionTimeout, int readTimeout)throws IOException {

            URLConnection connection =source.openConnection();

           connection.setConnectTimeout(connectionTimeout);

           connection.setReadTimeout(readTimeout);

            InputStream input =connection.getInputStream();

            copyInputStreamToFile(input,destination);

        }

拷贝一个字节流到一个文件中,如果这个文件不存在则新创建一个,存在的话将被重写进内容copyInputStreamToFile(InputStream source, File destination)

     public static voidcopyInputStreamToFile(InputStream source, File destination) throws IOException{

            try {

                FileOutputStream output =openOutputStream(destination);

                try {

                    IOUtils.copy(source,output);

                } finally {

                   IOUtils.closeQuietly(output);

                }

            } finally {

                IOUtils.closeQuietly(source);

            }

        }

递归的删除一个目录deleteDirectory(Filedirectory)

publicstatic void deleteDirectory(File directory) throws IOException {

            if (!directory.exists()) {

                return;

            }

   

            if (!isSymlink(directory)) {

                cleanDirectory(directory);

            }

   

            if (!directory.delete()) {

                String message =

                    "Unable to deletedirectory " + directory + ".";

                throw new IOException(message);

            }

        }


这篇关于FileUtils方法大全(1)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/932983

相关文章

【C++】_list常用方法解析及模拟实现

相信自己的力量,只要对自己始终保持信心,尽自己最大努力去完成任何事,就算事情最终结果是失败了,努力了也不留遗憾。💓💓💓 目录   ✨说在前面 🍋知识点一:什么是list? •🌰1.list的定义 •🌰2.list的基本特性 •🌰3.常用接口介绍 🍋知识点二:list常用接口 •🌰1.默认成员函数 🔥构造函数(⭐) 🔥析构函数 •🌰2.list对象

浅谈主机加固,六种有效的主机加固方法

在数字化时代,数据的价值不言而喻,但随之而来的安全威胁也日益严峻。从勒索病毒到内部泄露,企业的数据安全面临着前所未有的挑战。为了应对这些挑战,一种全新的主机加固解决方案应运而生。 MCK主机加固解决方案,采用先进的安全容器中间件技术,构建起一套内核级的纵深立体防护体系。这一体系突破了传统安全防护的局限,即使在管理员权限被恶意利用的情况下,也能确保服务器的安全稳定运行。 普适主机加固措施:

webm怎么转换成mp4?这几种方法超多人在用!

webm怎么转换成mp4?WebM作为一种新兴的视频编码格式,近年来逐渐进入大众视野,其背后承载着诸多优势,但同时也伴随着不容忽视的局限性,首要挑战在于其兼容性边界,尽管WebM已广泛适应于众多网站与软件平台,但在特定应用环境或老旧设备上,其兼容难题依旧凸显,为用户体验带来不便,再者,WebM格式的非普适性也体现在编辑流程上,由于它并非行业内的通用标准,编辑过程中可能会遭遇格式不兼容的障碍,导致操

透彻!驯服大型语言模型(LLMs)的五种方法,及具体方法选择思路

引言 随着时间的发展,大型语言模型不再停留在演示阶段而是逐步面向生产系统的应用,随着人们期望的不断增加,目标也发生了巨大的变化。在短短的几个月的时间里,人们对大模型的认识已经从对其zero-shot能力感到惊讶,转变为考虑改进模型质量、提高模型可用性。 「大语言模型(LLMs)其实就是利用高容量的模型架构(例如Transformer)对海量的、多种多样的数据分布进行建模得到,它包含了大量的先验

【北交大信息所AI-Max2】使用方法

BJTU信息所集群AI_MAX2使用方法 使用的前提是预约到相应的算力卡,拥有登录权限的账号密码,一般为导师组共用一个。 有浏览器、ssh工具就可以。 1.新建集群Terminal 浏览器登陆10.126.62.75 (如果是1集群把75改成66) 交互式开发 执行器选Terminal 密码随便设一个(需记住) 工作空间:私有数据、全部文件 加速器选GeForce_RTX_2080_Ti

【VUE】跨域问题的概念,以及解决方法。

目录 1.跨域概念 2.解决方法 2.1 配置网络请求代理 2.2 使用@CrossOrigin 注解 2.3 通过配置文件实现跨域 2.4 添加 CorsWebFilter 来解决跨域问题 1.跨域概念 跨域问题是由于浏览器实施了同源策略,该策略要求请求的域名、协议和端口必须与提供资源的服务相同。如果不相同,则需要服务器显式地允许这种跨域请求。一般在springbo

AI(文生语音)-TTS 技术线路探索学习:从拼接式参数化方法到Tacotron端到端输出

AI(文生语音)-TTS 技术线路探索学习:从拼接式参数化方法到Tacotron端到端输出 在数字化时代,文本到语音(Text-to-Speech, TTS)技术已成为人机交互的关键桥梁,无论是为视障人士提供辅助阅读,还是为智能助手注入声音的灵魂,TTS 技术都扮演着至关重要的角色。从最初的拼接式方法到参数化技术,再到现今的深度学习解决方案,TTS 技术经历了一段长足的进步。这篇文章将带您穿越时

模版方法模式template method

学习笔记,原文链接 https://refactoringguru.cn/design-patterns/template-method 超类中定义了一个算法的框架, 允许子类在不修改结构的情况下重写算法的特定步骤。 上层接口有默认实现的方法和子类需要自己实现的方法

使用JS/Jquery获得父窗口的几个方法(笔记)

<pre name="code" class="javascript">取父窗口的元素方法:$(selector, window.parent.document);那么你取父窗口的父窗口的元素就可以用:$(selector, window.parent.parent.document);如题: $(selector, window.top.document);//获得顶级窗口里面的元素 $(

消除安卓SDK更新时的“https://dl-ssl.google.com refused”异常的方法

消除安卓SDK更新时的“https://dl-ssl.google.com refused”异常的方法   消除安卓SDK更新时的“https://dl-ssl.google.com refused”异常的方法 [转载]原地址:http://blog.csdn.net/x605940745/article/details/17911115 消除SDK更新时的“