java byte数组转换成文件的两种方式
byte数组转换成文件
传统方式
FileOutputStream fos = new FileOutputStream(fileDest); fos.write(bytesArray); fos.close();
NIO方式
Path path = Paths.get(fileDest); Files.write(path, bytesArray);
byte数组转换成文件
传统方式
FileOutputStream fos = new FileOutputStream(fileDest);
fos.write(bytesArray);
fos.close();
NIO方式
Path path = Paths.get(fileDest);
Files.write(path, bytesArray);
File file = new File("/temp/1.txt");
//init array with file length
byte[] bytesArray = new byte[(int) file.length()];
FileInputStream fis = new FileInputStream(file);
fis.read(bytesArray); //read file into bytes[]
fis.close();
return bytesArray;
String filePath = "/temp/1.txt";
byte[] bFile = Files.readAllBytes(new File(filePath).toPath());
//or this
byte[] bFile = Files.readAllBytes(Paths.get(filePath));
import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import com.google.common.base.Function;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.RequestHandler;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
public class SwaggerConfig {
// 定义分隔符,配置Swagger多包
private static final String splitor = ";";
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
//.apis(RequestHandlerSelectors.basePackage("com.dayu.app.controller"))
// .apis(RequestHandlerSelectors.basePackage("com.dayu.clientweb.controller"))
.apis(basePackage("com.dayu.app.controller"+splitor+"com.dayu.clientweb.controller"))
.paths(PathSelectors.any())
.build();
}
/**
* 重写basePackage方法,使能够实现多包访问,复制贴上去
* @author teavamc
* @date 2019/1/26
* @return com.google.common.base.Predicate<springfox.documentation.RequestHandler>
*/
public static Predicate<RequestHandler> basePackage(final String basePackage) {
return input -> declaringClass(input).transform(handlerPackage(basePackage)).or(true);
}
private static Function<Class<?>, Boolean> handlerPackage(final String basePackage) {
return input -> {
// 循环判断匹配
for (String strPackage : basePackage.split(splitor)) {
boolean isMatch = input.getPackage().getName().startsWith(strPackage);
if (isMatch) {
return true;
}
}
return false;
};
}
private static Optional<? extends Class<?>> declaringClass(RequestHandler input) {
return Optional.fromNullable(input.declaringClass());
}
/**
* 创建该API的基本信息(这些基本信息会展现在文档页面中)
* 访问地址:http://项目实际地址/swagger-ui.html
* @return
*/
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("客户端接口")
.description("powered by dayu")
//.termsOfServiceUrl("http://swagger-ui.html/")
//.contact(contact)
.version("1.0")
.build();
}
}
在项目中,@Transactional(rollbackFor=Exception.class),如果类加了这个注解,那么这个类里面的方法抛出异常,就会回滚,数据库里面的数据也会回滚。
Mozilla 家推出的所有现代浏览器都可以使用的文件共享服务。
主要特性
不登录最大支持 1G,登录后最大2.5GB文件
到期自焚
24 小时后自动删除,支持最大7天过期时间
加密的共享链接
支持限制下载次数
支持手动失效
分享完成后文件自动从云中删除,如此您的资料将不会永远存于云端。
官方链接直达:https://send.firefox.com/