java文件目录实时同步的简单介绍

博主:adminadmin 2023-03-17 20:14:07 436

今天给各位分享java文件目录实时同步的知识,其中也会对进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

java中打开文件目录的递归并实现文件目录分层显示,纪录实时进度

试试这个代码。

import java.io.File;

import java.text.DecimalFormat;

import java.text.SimpleDateFormat;

import java.util.Date;

public class FilesAndDirectories {

public FilesAndDirectories() {

}

public void runTest() {

// list files and folders

String dir = "D:\\temp";

File file = new File(dir);

displayInfo(0, file);

}

private void displayInfo(int depth, File file) {

// Name, Date, Size, Attr

boolean executable = file.canExecute();

boolean readable = file.canRead();

boolean writable = file.canWrite();

boolean hidden = file.isHidden();

boolean directory = file.isDirectory();

long lastModified = file.lastModified();

long length = file.length();

String name = file.getName();

// create ASCII file structure

StringBuilder buf = new StringBuilder();

for (int i = 0; i  depth; ++i) {

buf.append("|");

}

if (directory) {

buf.append("+ ");

}

if (name.isEmpty()) {

buf.append(".");

} else {

buf.append(name);

}

// add modification date

buf.append("\t\t");

Date date = new Date(lastModified);

buf.append(new SimpleDateFormat().format(date));

buf.append("\t\t");

// add file size in kilobytes

long kb = length / 1024;

DecimalFormat format = new DecimalFormat();

format.setGroupingUsed(true);

buf.append(format.format(kb));

buf.append(" KB");

// add read, write, execute attribute flags

buf.append("\t\t");

if (hidden)

buf.append(".");

if (readable)

buf.append("R");

if (writable)

buf.append("W");

if (executable)

buf.append("X");

// print everything to the command line

System.out.println(buf.toString());

File[] children = file.listFiles();

if (children != null) {

for (File child : children) {

displayInfo(depth + 1, child);

}

}

}

public static void main(String[] args) {

new FilesAndDirectories().runTest();

}

}

java如何实现服务器之间的文件同步

给大家讲讲我的学习经历吧,开始的两年我学JAVA就是拿书看,练习书上的例子,但是一直没有好的效果。后来因为项目需要开始正式使用JAVA开发,我发现以前练习的东西都忘光了,所以不得不在拿起书看。也就是基本上做了无用功了。现在想来因为大部分是抄来的,不怎么动脑子,所以不清楚为什么要这样。所以我强烈建议你学习的时候给自己设定一个假想的项目目标,做一个东西出来,网页也好,application也好,这样你才会快速地学习。对java有了一定地感觉以后,你在去看他的DOCUMENT,看他的源码,我建议你从低版本的JAVA源码看起,因为他类少,看起来容易懂。然后你就会知道自己以前编码的东西那些是很幼稚的,是可以用一两句就能搞定的。如果你已经稍微有了些感觉,如果觉得合适也可以考虑参加一些培训,毕竟比自学要轻松些,另外还可以学到别人的一些经验,比如:“动力节点”或“王勇Java”一些学员反应不错的,也建议你们多了解一下其它的培训机构。Y.

java如何实现两台计算机之间文件夹同步更新

实现两台电脑同步文件夹的方法:

1、在登录完成之后,客户端会自动弹出配置向导。

2、选择目标文件夹之后,客户端会自动在该文件夹下面生成名为“”的同步文件夹。

即可实现成功。

关于java文件目录实时同步和的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。