如何找出使用java创建文件的时间,因为我希望删除早于某个时间段的文件,目前我正在删除目录中的所有文件,但这并不理想:
public void DeleteFiles() {
File file = new File("D:/Documents/NetBeansProjects/printing~subversion/fileupload/web/resources/pdf/");
System.out.println("Called deleteFiles");
DeleteFiles(file);
File file2 = new File("D:/Documents/NetBeansProjects/printing~subversion/fileupload/Uploaded/");
DeleteFilesNonPdf(file2);
}
public void DeleteFiles(File file) {
System.out.println("Now will search folders and delete files,");
if (file.isDirectory()) {
for (File f : file.listFiles()) {
DeleteFiles(f);
}
} else {
file.delete();
}
}
Run Code Online (Sandbox Code Playgroud)
以上是我当前的代码,我现在正在尝试添加一个if语句,只删除比一周更早的文件.
编辑:
@ViewScoped
@ManagedBean
public class Delete {
public void DeleteFiles() {
File file = new File("D:/Documents/NetBeansProjects/printing~subversion/fileupload/web/resources/pdf/");
System.out.println("Called deleteFiles");
DeleteFiles(file);
File file2 = new File("D:/Documents/NetBeansProjects/printing~subversion/fileupload/Uploaded/");
DeleteFilesNonPdf(file2);
}
public void DeleteFiles(File file) …
Run Code Online (Sandbox Code Playgroud) 我想知道是否可能,通过使用primefaces上传提前模式来限制用户仅上传一个文件,目前我有:
<p:fileUpload fileUploadListener="#{fileUploadController.handleFileUpload}"
mode="advanced"
multiple="false"
update="messages"
sizeLimit="100000000"
allowTypes="/(\.|\/)(gif|jpe?g|png|doc|docx|txt|pdf)$/"
auto="false"/>
<p:growl id="messages" showDetail="true"/>
Run Code Online (Sandbox Code Playgroud)
你可以看到我有muliple ="false",但用户仍然可以上传多个文件,任何提示?
编辑:
<p:fileUpload widgetVar="upload" fileUploadListener="#{fileUploadController.handleFileUpload}"
mode="advanced"
multiple="false"
update="messages"
label="Select File"
sizeLimit="100000000"
allowTypes="/(\.|\/)(gif|jpe?g|png|doc|docx|txt|pdf|html)$/"
auto="false"/>
<p:growl id="messages" showDetail="true"/>
Run Code Online (Sandbox Code Playgroud)
已添加上面的widgetVar
在我的js
<script type="text/javascript">
function Naviagtion()
{
//alert("Sent to the printing holding queue, you may close this app now, your work will still print out ");
window.setTimeout(afterDelay, 500);
location.href = 'FilesUploaded.xhtml';
}
upload.buttonBar.find('input[type=file]').change(function() {
if (this.value) {
var files = upload.uploadContent.find('.files tr');
if (files.length > 1) {
files.get(0).remove();
}
}
}); …
Run Code Online (Sandbox Code Playgroud) 我创建了一些Java代码来测量延迟,数据包大小和带宽.
计算延迟所需的等式是多少?
这是我目前正在使用但不确定它是正确的:
//latency = packetsize / delay + bandwidth
System.out.println("latency is " + (len*2) / (duration + transferRateMb));
Run Code Online (Sandbox Code Playgroud)
编辑长度乘以2以得到正确的字节值
duration是ping完成所需的时间
转移率由以下公民发现:
double transferRateMb = ((len*524288.0) / (duration/ 1000000000.0) ) ; //amount of data in megabytes transferred in 1 second.
Run Code Online (Sandbox Code Playgroud)
我已经阅读了各种指南,并且不理解它们,这只是项目的一个简单要求
这也将运行20次并取平均值
有任何想法吗 ?
目前正在检索我的机器上安装的默认打印机以进行打印.我希望能够选择文档转到哪台打印机.这样做的最佳方法是什么?
码:
PrintService[] services =
PrintServiceLookup.lookupPrintServices(psInFormat, null);
System.out.println("Printer Selected " + services[Printerinx]);
//PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
DocFlavor[] docFalvor = services[Printerinx].getSupportedDocFlavors();
for (int i = 0; i < docFalvor.length; i++) {
System.out.println(docFalvor[i].getMimeType());
}
Run Code Online (Sandbox Code Playgroud) 我不确定标题是否正确,但目前我有:
private String destinationPDF = "D:/Documents/NetBeansProjects/printing~subversion/fileupload/web/resources/pdf/";
public static String destination ="D:/Documents/NetBeansProjects/printing~subversion/fileupload/Uploaded/";
public String fileList = "D:/Documents/NetBeansProjects/printing~subversion/fileupload/web/resources/Directory Files/directoryFiles.txt";
Run Code Online (Sandbox Code Playgroud)
这些都是在课堂上定义的,实际上是2级,但这对我来说并不是一个完美的情况,我想知道有没有办法将位置存储在txt中并进行访问?
我创建了一些删除文件夹中所有文件的代码,问题是这很好,我希望能够删除目录中的所有文件,但保留文件夹完整,所以我不必进入每个文件文件夹并删除其中的文件,这是我目前的代码:
@ViewScoped
@ManagedBean
public class Delete {
public void DeleteFiles() throws IOException {
System.out.println("Called deleteFiles");
File file = new File("D:/Documents/NetBeansProjects/printing~subversion/fileupload/web/resources/pdf/up617648/");
String[] myFiles;
if (file.isDirectory()) {
myFiles = file.list();
for (int i = 0; i < myFiles.length; i++) {
File myFile = new File(file, myFiles[i]);
System.out.println(myFile);
myFile.delete();
}
DeleteFiles2();
}
}
public void DeleteFiles2() throws IOException {
System.out.println("Called deleteFiles2");
File file = new File("D:/Documents/NetBeansProjects/printing~subversion/fileupload/Uploaded/up617648/");
String[] myFiles;
if (file.isDirectory()) {
myFiles = file.list();
for (int i = 0; i < myFiles.length; i++) …
Run Code Online (Sandbox Code Playgroud) 试图编译和编程,这将帮助我对机器之间的消息传递进行基准测试,但我得到31个编译器错误:(
这些是我收到的错误:
PingPong.java:9: error: cannot find symbol
my_pe = MPI.COMM_WORLD.Rank();
^
symbol: variable my_pe
location: class PingPong
PingPong.java:10: error: cannot find symbol
npes = MPI.COMM_WORLD.Size();
^
symbol: variable npes
location: class PingPong
PingPong.java:11: error: cannot find symbol
for (log2nbyte = 0; log2nbyte <= LOG2N_MAX; ++log2nbyte) {
^
symbol: variable log2nbyte
location: class PingPong
PingPong.java:11: error: cannot find symbol
for (log2nbyte = 0; log2nbyte <= LOG2N_MAX; ++log2nbyte) {
^
symbol: variable log2nbyte
location: class PingPong
PingPong.java:11: error: cannot find symbol
for …
Run Code Online (Sandbox Code Playgroud)