org.nutz.lang.Files.findFile()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(5.1k)|赞(0)|评价(0)|浏览(103)

本文整理了Java中org.nutz.lang.Files.findFile()方法的一些代码示例,展示了Files.findFile()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Files.findFile()方法的具体详情如下:
包路径:org.nutz.lang.Files
类名称:Files
方法名:findFile

Files.findFile介绍

[英]从 CLASSPATH 下或从指定的本机器路径下寻找一个文件
[中]从 类路径下或从指定的本机器路径下寻找一个文件

代码示例

代码示例来源:origin: nutzam/nutz

@Override
public File cast(String src, Class<?> toType, String... args) throws FailToCastObjectException {
  return Files.findFile(src);
}

代码示例来源:origin: nutzam/nutz

/**
 * 根据一个文件路径建立一个输入流
 * 
 * @param path
 *            文件路径
 * @return 输入流
 */
public static InputStream fileIn(String path) {
  InputStream ins = Files.findFileAsStream(path);
  if (null == ins) {
    File f = Files.findFile(path);
    if (null != f)
      try {
        ins = Streams._input(f);
      }
      catch (IOException e) {}
  }
  if (null == ins) {
    // TODO 考虑一下,应该抛异常呢?还是返回null呢?
    throw new RuntimeException(new FileNotFoundException(path));
    // return null;
  }
  return buff(ins);
}

代码示例来源:origin: nutzam/nutz

public Object get(IocMaking ing) {
  return Files.findFile(path);
}

代码示例来源:origin: nutzam/nutz

/**
 * 根据一个文件路径建立一个输出流
 * 
 * @param path
 *            文件路径
 * @return 输出流
 */
public static OutputStream fileOut(String path) {
  return fileOut(Files.findFile(path));
}

代码示例来源:origin: nutzam/nutz

/**
 * 根据一个文件路径建立一个 UTF-8 文本输出流
 * 
 * @param path
 *            文件路径
 * @return 文本输出流
 */
public static Writer fileOutw(String path) {
  return fileOutw(Files.findFile(path));
}

代码示例来源:origin: nutzam/nutz

/**
 * 从 CLASSPATH 下或从指定的本机器路径下寻找一个文件
 * 
 * @param path
 *            文件路径
 * @param enc
 *            文件路径编码
 * @return 文件对象,如果不存在,则为 null
 */
public static File findFile(String path, String enc) {
  return findFile(path, ClassTools.getClassLoader(), enc);
}

代码示例来源:origin: nutzam/nutz

/**
 * 从classpath或当前目录下查找配置文件来进行初始化
 * @param name
 */
public void init(String name) throws IOException {
  init(new FileInputStream(Files.findFile(name)));
}

代码示例来源:origin: nutzam/nutz

/**
 * 从 CLASSPATH 下或从指定的本机器路径下寻找一个文件
 * 
 * @param path
 *            文件路径
 * @param klassLoader
 *            使用该 ClassLoader进行查找
 * 
 * @return 文件对象,如果不存在,则为 null
 */
public static File findFile(String path, ClassLoader klassLoader) {
  return findFile(path, klassLoader, Encoding.defaultEncoding());
}

代码示例来源:origin: nutzam/nutz

/**
 * 从 CLASSPATH 下或从指定的本机器路径下寻找一个文件
 * 
 * @param path
 *            文件路径
 * 
 * @return 文件对象,如果不存在,则抛出一个运行时异常
 */
public static File checkFile(String path) {
  File f = findFile(path);
  if (null == f)
    throw Lang.makeThrow("Fail to found file '%s'", path);
  return f;
}

代码示例来源:origin: nutzam/nutz

/**
 * 从 CLASSPATH 下或从指定的本机器路径下寻找一个文件
 * 
 * @param path
 *            文件路径
 * 
 * @return 文件对象,如果不存在,则为 null
 */
public static File findFile(String path) {
  return findFile(path, ClassTools.getClassLoader(), Encoding.defaultEncoding());
}

代码示例来源:origin: nutzam/nutz

final boolean deep,
                   final FileVisitor fv) {
File d = Files.findFile(path);
if (null == d)
  return;

代码示例来源:origin: nutzam/nutz

final boolean deep,
                final FileVisitor fv) {
File d = Files.findFile(path);
if (null == d)
  return;

代码示例来源:origin: nutzam/nutz

/**
 * 读取 UTF-8 文件全部内容
 * 
 * @param path
 *            文件路径
 * @return 文件内容
 */
public static String read(String path) {
  File f = Files.findFile(path);
  if (null == f)
    throw Lang.makeThrow("Can not find file '%s'", path);
  return read(f);
}

代码示例来源:origin: nutzam/nutz

/**
 * 读取文件全部字节,并关闭文件
 * 
 * @param path
 *            文件路径
 * @return 文件的字节内容
 */
public static byte[] readBytes(String path) {
  File f = Files.findFile(path);
  if (null == f)
    throw Lang.makeThrow("Can not find file '%s'", path);
  return readBytes(f);
}

代码示例来源:origin: nutzam/nutz

/**
 * 对一个图像进行旋转
 * 
 * @param srcPath
 *            原图像文件路径
 * @param taPath
 *            转换后的图像文件路径
 * @param degree
 *            旋转角度, 90 为顺时针九十度, -90 为逆时针九十度
 * @return 旋转后得图像对象
 */
public static BufferedImage rotate(String srcPath, String taPath, int degree)
    throws IOException {
  File srcIm = Files.findFile(srcPath);
  if (null == srcIm)
    throw Lang.makeThrow("Fail to find image file '%s'!", srcPath);
  File taIm = Files.createFileIfNoExists(taPath);
  return rotate(srcIm, taIm, degree);
}

代码示例来源:origin: nutzam/nutz

/**
 * 根据给定的起始坐标点与结束坐标点来剪切一个图片,令其符合给定的尺寸,并将其保存成目标图像文件
 * <p>
 * 图片格式支持 png | gif | jpg | bmp | wbmp
 * 
 * @param srcPath
 *            源图像文件对象
 * @param taPath
 *            目标图像文件对象
 * @param startPoint
 *            起始坐标点,其值[x, y]为相对原图片左上角的坐标
 * @param endPoint
 *            结束坐标点,其值[x, y]为相对原图片左上角的坐标
 * @return 被转换前的图像对象
 * 
 * @throws IOException
 *             当读写文件失败时抛出
 */
public static BufferedImage clipScale(String srcPath,
                   String taPath,
                   int[] startPoint,
                   int[] endPoint)
    throws IOException {
  File srcIm = Files.findFile(srcPath);
  if (null == srcIm)
    throw Lang.makeThrow("Fail to find image file '%s'!", srcPath);
  File taIm = Files.createFileIfNoExists(taPath);
  return clipScale(srcIm, taIm, startPoint, endPoint);
}

代码示例来源:origin: nutzam/nutz

/**
 * 自动缩放剪切一个图片,令其符合给定的尺寸,并将其保存到目标图像路径
 * <p>
 * 图片格式支持 png | gif | jpg | bmp | wbmp
 * 
 * @param srcPath
 *            源图像路径
 * @param taPath
 *            目标图像路径,如果不存在,则创建
 * @param w
 *            宽度
 * @param h
 *            高度
 * 
 * @return 被转换前的图像对象
 * 
 * @throws IOException
 *             当读写文件失败时抛出
 */
public static BufferedImage clipScale(String srcPath, String taPath, int w, int h)
    throws IOException {
  File srcIm = Files.findFile(srcPath);
  if (null == srcIm)
    throw Lang.makeThrow("Fail to find image file '%s'!", srcPath);
  File taIm = Files.createFileIfNoExists(taPath);
  return clipScale(srcIm, taIm, w, h);
}

代码示例来源:origin: nutzam/nutz

Color bgColor)
  throws IOException {
File srcIm = Files.findFile(srcPath);
if (null == srcIm)
  throw Lang.makeThrow("Fail to find image file '%s'!", srcPath);

代码示例来源:origin: nutzam/nutz

String[] ss = Strings.splitIgnoreBlank(str, "\n");
for (String s : ss) {
  File f = Files.findFile(s);
  if (null == f) {
    throw Lang.makeThrow("Fail to found path '%s' in CLASSPATH or File System!", s);

代码示例来源:origin: org.nutz/nutz

/**
 * 从 CLASSPATH 下或从指定的本机器路径下寻找一个文件
 * 
 * @param path
 *            文件路径
 * @param enc
 *            文件路径编码
 * @return 文件对象,如果不存在,则为 null
 */
public static File findFile(String path, String enc) {
  return findFile(path, ClassTools.getClassLoader(), enc);
}

相关文章