资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

文件管理源代码java,文件管理软件开源

求一个简单的用java语言编写的文件管理器的源代码????

public class complie {

在松溪等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供成都网站设计、成都网站建设 网站设计制作定制网站制作,公司网站建设,企业网站建设,高端网站设计,成都全网营销推广,外贸网站建设,松溪网站建设费用合理。

int i,j;

public complie(int i,int j)//构建一个复数类

{

this.i=i;

this.j=j;

}

complie add(complie c)//复数加法

{

int l,k;

l=c.i+i;

k=c.j+j;

return (new complie(l,k));

}

complie cut(complie c)//复数减法

{

int l,k;

l=i-c.i;

k=j-c.j;

return (new complie(l,k));

}

void ToString()//将复数输出

{

System.out.println("复数为:"+i+"+"+j+"i");

}

public static void main(String[] args)

{

complie a=new complie(4,5);

complie b=new complie(2,3);

System.out.println("构造的复数类为:");

a.ToString();

b.ToString();

System.out.println("运算复数a+b=:");

a.add(b).ToString();

System.out.println("运算复数a-b=:");

a.cut(b).ToString();

}

}

java中File源代码问题

这是一个抽象类,根据不同的操作系统会有不同的实现。典型的windows和unix操作系统对文件的管理就不一样。

getFileSystem()是一个本地方法,看不到源代码。

FileSystem类本来就不是提供给程序员使用的。

反编译后的源代码如下:

package java.io;

// Referenced classes of package java.io:

// IOException, File

abstract class FileSystem

{

FileSystem()

{

}

public static native FileSystem getFileSystem();

public abstract char getSeparator();

public abstract char getPathSeparator();

public abstract String normalize(String s);

public abstract int prefixLength(String s);

public abstract String resolve(String s, String s1);

public abstract String getDefaultParent();

public abstract String fromURIPath(String s);

public abstract boolean isAbsolute(File file);

public abstract String resolve(File file);

public abstract String canonicalize(String s)

throws IOException;

public abstract int getBooleanAttributes(File file);

public abstract boolean checkAccess(File file, int i);

public abstract boolean setPermission(File file, int i, boolean flag, boolean flag1);

public abstract long getLastModifiedTime(File file);

public abstract long getLength(File file);

public abstract boolean createFileExclusively(String s)

throws IOException;

public abstract boolean delete(File file);

public abstract String[] list(File file);

public abstract boolean createDirectory(File file);

public abstract boolean rename(File file, File file1);

public abstract boolean setLastModifiedTime(File file, long l);

public abstract boolean setReadOnly(File file);

public abstract File[] listRoots();

public abstract long getSpace(File file, int i);

public abstract int compare(File file, File file1);

public abstract int hashCode(File file);

private static boolean getBooleanProperty(String s, boolean flag)

{

String s1 = System.getProperty(s);

if(s1 == null)

return flag;

return s1.equalsIgnoreCase("true");

}

public static final int BA_EXISTS = 1;

public static final int BA_REGULAR = 2;

public static final int BA_DIRECTORY = 4;

public static final int BA_HIDDEN = 8;

public static final int ACCESS_READ = 4;

public static final int ACCESS_WRITE = 2;

public static final int ACCESS_EXECUTE = 1;

public static final int SPACE_TOTAL = 0;

public static final int SPACE_FREE = 1;

public static final int SPACE_USABLE = 2;

static boolean useCanonCaches;

static boolean useCanonPrefixCache;

static

{

useCanonCaches = true;

useCanonPrefixCache = true;

useCanonCaches = getBooleanProperty("sun.io.useCanonCaches", useCanonCaches);

useCanonPrefixCache = getBooleanProperty("sun.io.useCanonPrefixCache", useCanonPrefixCache);

}

}

急求Java简单文件管理类程序

这是别人写好的

package sunnykid.file;

import java.io.*;

import sunnykid.text.SunnykidNumber;

/**

* p标题: JAVA文件操作工具类/p

* br

* p描述: 阳光软体工作室常用工具包/p

* br

* p版权: 版权所有 (c) 2007/p

* br

* p组织: 阳光软体工作室/p

*

* @author 钟晓籁

* @version V1.0

*/

public class FileOperator {

/**

* 不带参数的构造函数

*/

public FileOperator() {

super();

}

/**

* 删除指定的文件

* @param filepath String 待删除的文件路径及名称

* @throws IOException

*/

public void delete(String filepath) throws IOException {

Runtime rt = Runtime.getRuntime();

rt.exec("cmd /c del " + filepath);

}

/**

* 将字符串写入文件

* @param content String 待写入的字符串内容

* @param filepath String 待写入的文件路径及名称

* @throws IOException

*/

public void write(String content, String filepath) throws IOException {

File file = new File(filepath);

FileWriter fw = new FileWriter(file);

fw.write(content);

fw.close();

}

/**

* 读取文件中的内容

* @param filepath String 待读取的文件路径及名称

* @return String 返回从文件中读取的字符串内容

* @throws IOException

*/

public String read(String filepath) throws IOException {

int text = 0;

File file = new File(filepath);

FileReader fr = new FileReader(file);

int len = (int) file.length();

char[] buffer = new char[len];

while (fr.ready()) {

text = text + fr.read(buffer, text, len - text);

}

fr.close();

String content = new String(buffer, 0, text);

return content;

}

/**

* 判断一个文件是否存在

* @param filepath String 待判断的文件路径及名称

* @return boolean 返回文件是否存在结果

*/

public boolean isExist(String filepath) {

File file = new File(filepath);

if (file.exists()) {

return true;

} else {

return false;

}

}

/**

* 重命名文件或目录

* @param oldname String 重命名前的文件或目录名称

* @param newname String 重命名后的文件或目录名称

* @return boolean 返回操作是否成功结果

*/

public boolean rename(String oldname, String newname) {

File oldfile = new File(oldname);

File newfile = new File(newname);

boolean success = oldfile.renameTo(newfile);

return success;

}

/**

* 剪切指定文件至指定的目录

* @param from String 源文件的路径及名称

* @param to String 目标路径及名称

*/

public void move(String from, String to) {

File oldfile = new File(from);

File newfile = new File(to);

oldfile.renameTo(newfile);

}

/**

* 拷贝指定文件至指定的目录

* @param from String 源文件的路径及名称

* @param to String 目标路径及名称

* @throws IOException

*/

public void copy(String from, String to) throws IOException {

int BUFF_SIZE = 100000;

byte[] buffer = new byte[BUFF_SIZE];

InputStream in = null;

OutputStream out = null;

try {

in = new FileInputStream(from);

out = new FileOutputStream(to);

while (true) {

synchronized (buffer) {

int amountRead = in.read(buffer);

if (amountRead 0) {

break;

}

out.write(buffer, 0, amountRead);

}

}

} finally {

if (in != null) {

in.close();

}

if (out != null) {

out.close();

}

}

}

/**

* 获取文件扩展名

* @param filename String 需要获取大小的文件之完整路径

* @return String 返回文件扩展名

*/

public String getExtension(String filename) {

String defExt = null;

if ((filename != null) (filename.length() 0)) {

int i = filename.lastIndexOf('.');

if ((i 0) (i (filename.length() - 1))) {

defExt = filename.substring(i + 1);

}

}

return defExt;

}

/**

* 获取文件字节数

* @param filename String 需要获取大小的文件之完整路径

* @return long 返回文件大小字节数

*/

public long fileSize(String filename) {

long size = 0L;

File file = new File(filename);

if (this.isExist(filename) == true) {

size = file.length();

}

return size;

}

/**

* 获取标准单位之文件大小

* @param bytesize long 需要转换为标准单位的文件之字节数

* @return String 返回标准单位之文件大小

*/

public String switchSize(long bytesize) {

String size = "";

SunnykidNumber sn=new SunnykidNumber();

float number = 0.0f;

if (bytesize = 0) {

size = "0Bytes";

} else if (bytesize 1024) {

size = String.valueOf(size) + "Bytes";

} else if (bytesize 1048576) {

number = (float) bytesize / 1024;

size = sn.parseCurrency(number) + "KB";

} else if (bytesize 1073741824) {

number = (float) bytesize / 1024 / 1024;

size = sn.parseCurrency(number) + "MB";

} else if (bytesize 1099511627776L) {

number = (float) bytesize / 1024 / 1024 / 1024;

size = sn.parseCurrency(number) + "GB";

}

return size;

}

}

====================

package sunnykid.text;

import java.text.*;

/**

* p标题: 用於操作数字的类/p

* br

* p描述: 阳光软体工作室常用工具包/p

* br

* p版权: 版权所有 (c) 2007/p

* br

* p组织: 阳光软体工作室/p

*

* @author 钟晓籁

* @version V1.0

*/

public class SunnykidNumber {

/**

* 不带参数的构造函数

*/

public SunnykidNumber() {

super();

}

/**

* 将数字格式化成货币样式

* @param unfmt_dbl double 未经格式化的数字

* @return String 返回按照货币样式格式化后的字符串

*/

public String getCurrency(double unfmt_dbl) { //双精度数转化成货币类型两位小数

NumberFormat nf = NumberFormat.getCurrencyInstance(); //按照货币类型格式化数字

String fmted_str = nf.format(unfmt_dbl);

return fmted_str;

}

/**

* 按照货币类型格式化数字

* @param unfmt_dbl double 未经格式化的数字

* @return String 返回按照货币类型格式化后的字符串

*/

public String parseCurrency(double unfmt_dbl) { //双精度数转化成货币类型两位小数的字符串

DecimalFormat df = new DecimalFormat("#.00"); //按照货币类型格式化数字

String fmted_str = df.format(unfmt_dbl);

return fmted_str;

}

/**

* 双精度小数转化成百分数

* @param unfmt_dbl double 未经格式化的数字

* @return String 返回按照百分比样式格式化后的字符串

*/

public String parsePercect(double unfmt_dbl) { //双精度小数转化成百分数

NumberFormat nf = NumberFormat.getPercentInstance(); //按照百分比格式化数字

// nf.setMinimumIntegerDigits(integ);// 设置数的整数部分所允许的最大位数

// nf.setMaximumFractionDigits(fract);// 设置数的小数部分所允许的最大位数

String fmted_str = nf.format(unfmt_dbl);

return fmted_str;

}

/**

* 双精度小数四舍五入为整数

* @param unfmt_dbl double 未经转化的小数

* @return int 小数四舍后得到的整数

*/

public int roundNumber(double unfmt_dbl) {

String temp_str = String.valueOf(unfmt_dbl); //将小数转化为字符串

if (temp_str.indexOf(".") = 0) {

}

int indexOfDot = temp_str.indexOf("."); //获取小数点位置

int temp_int = Integer.parseInt(temp_str.substring(indexOfDot + 1,

indexOfDot + 2));

if (temp_int 5) { //判断小数点后一位的数字是否大於5

return Integer.parseInt(temp_str.substring(0, indexOfDot)); //四舍

} else {

return Integer.parseInt(temp_str.substring(0, indexOfDot)) + 1; //五入

}

}

}


本文名称:文件管理源代码java,文件管理软件开源
分享地址:http://cdkjz.cn/article/dsejepi.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220