1 /* 2 * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 package com.sk.ts.utils; 17 18 import java.util.regex.Pattern; 19 20 /** 21 * 文本文件工具 22 * 23 * @author: xudong 24 * @see: file utils 25 * @version: v1.0.0 26 * @since 2022-02-21 27 */ 28 public class FileUtil { 29 /** 30 * 获取换行符 31 * 32 * @return 换行符 33 */ getNewline()34 public static String getNewline() { 35 return System.getProperty("line.separator"); 36 } 37 38 /** 39 * 正则匹配所选文件名是否符合规范 40 * 41 * @param fileName 文件名 42 * @return boolean 是否匹配 43 */ patternFileName(String fileName)44 public static boolean patternFileName(String fileName) { 45 String pattern = "(([.a-z_A-Z0-9]+).h)"; 46 return Pattern.matches(pattern, fileName); 47 } 48 49 /** 50 * 正则匹配所选文件名是否符合规范 51 * 52 * @param fileName 文件名 53 * @return boolean 是否匹配 54 */ patternFileNameH(String fileName)55 public static boolean patternFileNameH(String fileName) { 56 String pattern = "([.a-z_A-Z0-9]+).h"; 57 return Pattern.matches(pattern, fileName); 58 } 59 } 60