62,616
社区成员
发帖
与我相关
我的任务
分享
public boolean createLicense(String filename) throws LogicException
{
ESMEncrypt encrypt = new ESMEncrypt();
String strInput = "the content of this file";
// 判断当前操作系统类型
File parentFile = null;
File file = null;
try
{
parentFile=new File(getClass().getResource("/myfile").toURI());
if(parentFile.isDirectory())
{
File child=new File(parentFile,filename);
if(!child.exists())
{
child.mkdir();
}
String osType = child.getPath() + "\\file.sss";
if (osType != null)
{
file = new File(osType);
}
// 如果已经有
if (file.exists())
{
file.delete();
}
if (!file.exists())
{
file.createNewFile();
}
FileOutputStream outs = new FileOutputStream(file);
outs.write(encrypt.encrypt(strInput.getBytes(), Cipher.ENCRYPT_MODE));
outs.close();
}
}
catch (Exception e)
{
e.printStackTrace();
return false;
}
return true;
}
public static boolean delAllFile(String path)
{
boolean flag=false;
File file=new File(path);
if(file.exists())
{
if(file.isDirectory())
{
String[] tempList=file.list();
File temp=null;
for(int i=0; i<tempList.length; i++)
{
if(path.endsWith(File.separator))
{
temp=new File(path + tempList[i]);
}
else
{
temp=new File(path+File.separator+tempList[i]);
}
if(temp.isFile())
{
temp.delete();
}
}
}
}
return flag;
}
public static boolean delFolders(String folderPath)
{
boolean flag=false;
try
{
if(delAllFile(folderPath))
{
String filePath=folderPath;
File myFilePath=new File(filePath);
if(myFilePath.delete())
{
flag=true;
}
}
}
catch (Exception e)
{
flag=false;
e.printStackTrace();
}
return flag;
}