java项目 建文件夹_java创建文件夹

用java建立文件夹

package test;

public class muluTest

{

public static void main(String[] args)

{

muluTest mulutest = new muluTest();

mulutest.newFolder("D:\\abcds");

}

public   void   newFolder(String  folderPath)

{

String   filePath   =   folderPath;

filePath   =  filePath.toString();java.io.File   myFilePath  =   new   java.io.File(filePath);try

{

if(myFilePath.isDirectory()){

System.out.println("the directory isexists!");

}

else

{myFilePath.mkdir();System.out.println("新建目录成功");

}

}

catch   (Exception   e)

{

System.out.println("新建目录操作出错");

e.printStackTrace();

}

}

}

package ifpre.web;

import gxdmif.GXStringUtil;

import java.io.DataOutputStream;

import java.io.File;

import java.io.FileOutputStream;

import java.io.InputStream;

import org.springframework.web.multipart.MultipartFile;

public  class  SaveFile   {

public   boolean  save(String path, MultipartFile file)  throws Exception   {

GXStringUtil gx  =   new GXStringUtil();

boolean  result  =  false ;

File dirFile  = null ;

try  {

dirFile  =   new File(path);

if ( ! (dirFile.exists()) &&   !(dirFile.isDirectory()))  {

boolean  creadok =  dirFile.mkdirs();

if (creadok)  {

System.out.println( "ok:创建文件夹成功!" );

} else  {

System.out.println( "err:创建文件夹失败!" );

}

}

} catch (Exception e)  {

e.printStackTrace();

System.out.println(e);

return   false ;

}

if  (file  !=   null   &&  ! file.isEmpty())   {

String fullPath  =  path +  System.getProperty( "file.separator " )

+ gx.netStringToGBK(file.getOriginalFilename());

DataOutputStream out  =   null ;

InputStream is  =   null ;

try    {

out  =  new  DataOutputStream( new  FileOutputStream(fullPath));

is  = file.getInputStream();

byte [] buffer  =  new   byte [ 1024 ];

while  (is.read(buffer)  >  0 )   {

out.write(buffer);

}

}   finally    {

if  (is !=   null )   {

is.close();

}

if  (out !=   null )   {

out.close();

}

}

result  =   true ;

}

return  result;

}

public   boolean  delete(String path, MultipartFile file)  throws Exception   {

GXStringUtil gx  =   new GXStringUtil();

boolean  result  =  false ;

if  (file  !=  null   &&   ! file.isEmpty())   {

String fullPath  =  path +  System.getProperty( "file.separator " )

+  gx.netStringToGBK(file.getOriginalFilename());

try    {

File file2  =  new  File(fullPath);

file2.delete();

result  =  true ;

}   catch  (Exception e)   {

e.printStackTrace();

result  =   false;

}

}

return  result;

}

public     boolean    deleteFolder(File   folder)    {

boolean  result  =  false ;

try  {

String   childs[]   =    folder.list();

if    (childs   ==     null     ||   childs.length    <=     0 )    {

if(folder.delete())  {

result  =  true ;

}

}   else {

for    ( int   i    =     0 ;  i   

String   childName   =    childs[i];

String   childPath   =

folder.getPath()    +    File.separator    +   childName;

File   filePath   =     new    File(childPath);

if    (filePath.exists()    &&    filePath.isFile())     {

if(filePath.delete())  {

result  =  true ;

} else  {

result  =  false ;

break ;

}

}

else     if   (filePath.exists()    &&    filePath.isDirectory())     {

if(deleteFolder(filePath))  {

result  =  true ;

} else {

result  =  false ;

break ;

}

}

}

}

folder.delete();

} catch (Exception e)  {

e.printStackTrace();

result  =  false ;

}

return  result;

}

}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/380831.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

stl vector 函数_vector :: push_back()函数,以及C ++ STL中的示例

stl vector 函数C vector :: push_back()函数 (C vector::push_back() function) vector::push_back() is a library function of "vector" header, it is used to insert/add an element at the end of the vector, it accepts an element of the same type and ad…

Virtools自己编译播放器

virtools可以自己是一sdk来编写播放器&#xff0c;在安装目录的sdk下有一个CustomPlayer的例子。位于StandalonePlayer目录下。 改例子包含了一个readme.txt文件来描述如何使用CustomPlayer.exe。 运行是会出现一个提示框&#xff0c;可以把CustomPlayerApp.cpp中的_Publishing…

php的超全局变量

php的超全局变量如下图 所有的超全局变量都是数组类型&#xff0c;并且php已经帮我们定义好了&#xff0c;下面重点介绍几个 $_GET:用来保存get方式提交的数据 <!DOCTYPE html> <html><head><meta charset"UTF-8"><title>测试$_GET…

java解析xml中文字符乱码_各种Java中文乱码的处理方法

对于Java&#xff0c;由于默认的编码方式是UNICODE&#xff0c;所以用中文也易出问题&#xff0c;常见的解决是&#xff1a;String s2 new String(s1.getBytes(“ISO-8859-1”),”GBK”);1、utf8解决JSP中文乱码问题一般说来在每个页面的开始处&#xff0c;加入&#xff1a;pa…

赚钱绝对是一种智慧

赚钱绝对是一种智慧来的&#xff0c;如同做生意一样。当然&#xff0c;它是另一种智慧。 在中国儒家的观念里&#xff0c;赚钱是低级的行为来的&#xff0c;商人被打入社会下层&#xff0c;经商充其量只能算做体力劳动。中国有一句话&#xff1a;无奸不商。说得好&#xff01;这…

c语言中负数_C语言中负数的模数

c语言中负数C中的模数运算符(&#xff05;)运算符 (The modulus operator (%) operator in C) The modulus operator is an arithmetic operator in C language; it is a binary operator and works with two operands. It is used to find the remainder. 模运算符是C语言中的…

php可变变量$$

$$:将变量名存储到另一个变量中&#xff0c;比如&#xff1a; <?php echo <meta charset"utf-8">;$a"小何流水人家";$ba;echo $$b; ?>$$b:$b‘a’&#xff0c;a和前面的$结合形成变量$a&#xff0c;然后输出变量a的内容

炒房客身家过亿 曝炒房心得及地产10大真相

2008年1月&#xff0c;怀揣着挖煤炭赚来的2000万RMB&#xff0c;我加入了炒房的行列。2009年10月&#xff0c;我的收益已经到了2亿&#xff0c;同时&#xff0c;我自认为当前炒房技术已经炉火纯青。首先声明&#xff0c;我是1992年初中肄业&#xff08;差半年毕业&#xff0c;因…

python求素数算法_Python程序最多可计算n个质数(使用不同算法)

python求素数算法There are various methods through which we can calculate prime numbers upto n. 我们可以通过多种方法来计算最大为n的素数 。 1) General Method 1)一般方法 In this method, we usually run two for loops in which the First one is used to increase…

cmd运行php文件以及环境配置出现的问题、 php.exe不是内部或外部命令,也不是可运行的程序 或批处理文件、PHP startup: Unable to load dynamic library

我用php.exe远行php文件出现了几个问题&#xff0c;先说一下怎么解决这些问题的&#xff0c;然后再说怎么运行 首先是出现 ‘php.exe’ 不是内部或外部命令,也不是可运行的程序 或批处理文件&#xff0c;查了一下&#xff0c;是没有配置php环境变量&#xff0c;配置php环境的过…

开启和关闭wifi的代码段

1、需要申请的权限android.permission.ACCESS_WIFI_STATE android.permission.CHANGE_WIFI_STATE android.permission.WAKE_LOCK 2、获取WifiManagerwifiManager (WifiManager) this.getSystemService(Context.WIFI_SERVICE); 3、开启、关闭wifiif (wifiManager.isWifiEnable…

java boolean例子_Java Field setBoolean()用法及代码示例

java.lang.reflect.Field的setBoolean()方法用于将字段的值设置为指定对象上的布尔值。当需要将对象的字段的值设置为布尔值时&#xff0c;可以使用此方法在对象上设置值。用法:public void setBoolean(Object obj, boolean z)throws IllegalArgumentException,IllegalAccessEx…

Python程序打印字符串,从字符串中提取字符

In this program – we are going to learn how can we complete string, print specific characters, print a range of the characters, print string multiple times (using * operator), print multiple stings by concatenating them etc. 在此程序中&#xff0c;我们将学…

php定义常量、判断有没有被定义、预定义常量、显示所有常量

常量一旦被定义&#xff0c;在脚本的其他任何地方都不能被改变&#xff0c;注意&#xff1a;常量名的前面没有$ 语法&#xff1a;define(name,value,case_insensitive ) name:常量名&#xff0c;一般常量名都大写value&#xff1a;常量值case_insensitive &#xff1a;bool类型…

Word——Word中粘贴Visio图只显示下面一部分

1. 问题发现 前段时间帮朋友整理一篇学位论文&#xff0c;发现在Word中粘贴画好的Visio图时&#xff0c;只能显示Visio图的下面一部分&#xff08;一行宽左右&#xff09;。通过&#xff1a;右键-->“设置图片格式”-“版式”-“环绕方式”-“嵌入型”&#xff0c;发现环绕方…

java server模式 设置_JVM client模式和Server模式的区别

这里向大家描述一下JVM client模式和Server模式两者的区别和联系&#xff0c;JVM如果不显式指定是-Server模式还是-client模式&#xff0c;JVM能够根据下列原则进行自动判断(适用于Java5版本或者Java以上版本)。JVM client模式和Server模式JVM Server模式与client模式启动&…

python 整数 1字节_Python程序打印代表整数的字节数组

python 整数 1字节Given an integer number and we have to convert it into a byte array in Python. 给定一个整数&#xff0c;我们必须在Python中将其转换为字节数组。 To convert an integer number into bytes (byte array), we use to_bytes() method of int class, it …

PHP的数据类型、浮点型比较

在介绍php的数据类型前&#xff0c;先说一说强数据类型和弱数据类型。 弱数据类型&#xff1a;变量的类型取决于存放值的类型 强数据类型&#xff1a;变量的类型取决于申明变量时的类型。比如申明变量是A类型就不能存放B类型 PHP是弱数据类型&#xff0c;php支持8种原始数据类型…

《测试驱动开发》读书笔记

最终目标是整洁可用的代码 我们不是从建立对象开始&#xff0c;而是从测试开始 了解需求-》设计测试 -》让测试通过 列出所有已知问题&#xff0c;然后一个一个解决&#xff1b; 培养将软件开发化为一小步一小步开发任务的能力 测试程序与代码所存在的问题不在于重复设计&#…

java sampling_Java机器学习库ML之三Sampling(采样)

场景&#xff1a;从样本集中采样80%用于训练&#xff0c;20%用于验证。参考代码如下&#xff1a;package com.gddx;import java.io.File;import java.util.Map;import libsvm.LibSVM;import net.sf.javaml.classification.Classifier;import net.sf.javaml.classification.eval…