如何获得java.io.File.list()与Windows资源管理器中相同的顺序?
在程序中,我正在创建Temp文件夹,例如Temp1,Temp2依此类推.但是当我使用java.io.File.list()检索文件夹列表,它给人的Temp1,Temp10等等.
请告诉我们如何获得与Windows资源管理器中显示的相同的订单列表?
谢谢
给定一种Collection类型T,将Java 8转换List为类型的Java 8惯用方法是什么T?是以下吗?:
Collection<Foo> f;
f.stream().collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud) 在另一个堆栈中创建嵌套堆栈时,它获得的名称如下:
<name-of-the-parent-stack>-<resource-name>-<UUID>
Run Code Online (Sandbox Code Playgroud)
看起来不太好。同时,我找不到可以指定所需名称的“ AWS :: CloudFormation :: Stack ”类型的任何属性。是否可以定义其名称?
如果我创建一个带注释的bean,@RequestScoped我希望它会为每个新请求实例化一个新的代理实例.
另一方面,每个请求都与其自己的线程相关联.
我的问题是:如果新请求重用以前从池中创建的线程,CDI会重用以前创建的bean/service的代理对象吗?
我遇到了以下问题.我正在使用的Weld实现CDI.
我发现如果服务注释了,@ApplicationScoped那么@PostConstruct在第一次使用服务之前不会调用section.这是一个重现此行为的代码:
import org.jboss.weld.environment.se.Weld;
import org.jboss.weld.environment.se.WeldContainer;
import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.spi.CDI;
public class TestCdi {
public static void main(String[] args) {
try (WeldContainer weldContainer = new Weld().containerId("test").initialize()) {
FooService fooService = CDI.current().select(FooService.class).get();
fooService.test();
System.out.println("Done");
}
}
@ApplicationScoped
public static class FooService {
@PostConstruct
public void init() {
System.out.println("Post construct");
}
public void test() {
System.out.println("test");
}
}
}
Run Code Online (Sandbox Code Playgroud)
因此,如果fooService.test();被注释,则FooService.init()不会被调用.但删除@ApplicationScoped它再次工作!
这对我来说似乎很奇怪,我无法找到和描述这种行为.
此外,规范javax.inject.Provider.get()说:
提供完全构造和注入的T实例.
那么,问题是什么?它是这样设计还是这个bug?对我来说更重要的是:如何绕过这个问题?我需要我的服务 …
我试图编写一个简单的函数来释放动态分配的内存
typedef struct list{
int data;
struct list * link;
} list;
list * head = NULL;
void release(list * head_new){
list * dummy = NULL;
while(head_new != NULL){
dummy = head_new->link;
printf("before freeing %p, %d", head_new->link, head_new->data);
free(head_new);
printf("free returns %p, %d", head_new->link, head_new->data);
head_new = dummy
}
}
Run Code Online (Sandbox Code Playgroud)
使用主函数值被赋予列表,并且即使在释放head_new节点之后,在该特定函数中也会打印一些值
1
12
1
123
1 12 1 123 before freeing 00622A40, 1
free returns 006200C4, 6433408
before freeing 00622A60, 12
free returns 006200C4, 6434048
before freeing 00622A70, 1
free …Run Code Online (Sandbox Code Playgroud) 代码如下:
public static void main(String[] args){
Date date = new Date();
DateFormat dateFormat= new SimpleDateFormat("dd-MMM-yyy");
try{
Date formattedDate = dateFormat.parse(date.toString());
System.out.println(formattedDate.toString());
}catch(ParseException parseEx){
parseEx.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,dateFormat.parse(date.toString())抛出无法解析的日期异常:Unparseable date: "Mon Jan 28 18:53:24 IST 2013
我无法弄清楚原因。
似乎ResultSet空的标准检查在Spring的JDBC中不起作用ResultSetExtractor。我通过以下方式使用它:
return jdbcTemplate.query(sql, ps -> {
ps.setLong(1, fooParam1);
ps.setLong(2, fooParam2);
}, rs -> {
return rs.getLong(1);
});
Run Code Online (Sandbox Code Playgroud)
那么ResultSet在这种模式下检查空度的正确方法是什么?
有什么方法可以访问$route内部指令功能?
我基本上想要的是知道当前templateUrl,说:
app.directive("scrollable", function ($document) {
return {
restrict: 'A',
link: function (scope, element, attrs) {
$document.bind('scroll', function (evt) {
console.log($route.current.templateUrl); // $route is undefined!
});
}
};
});
Run Code Online (Sandbox Code Playgroud)
PS我是AngularJS的新手,不要那么严谨:)