--------------------------------
java得到文件路径下的所有文件名
/*
*@param 声明File对象,指定参数filePath
*/
File dir = new File(filePath); //返回此抽象路径下的文件
File[] files = dir.listFiles();
if (files == null) return;
for (int i = 0; i < files.length; i++) { //判断此文件是否是一个文件
if (!files[i].isDirectory()){
System.out.println(files[i].getName());
}
}
--------------------------------
/**
* 上传文件
*
* @param file 上传文件实体
* @param filename 上传文件新命名
* @param dir 上传文件目录
* @return
*/
public static boolean uploadFile(File file, String dir, String filename) {
boolean ret = false;
try {
if (file != null) {
java.io.File filePath = new java.io.File(dir);
if (!filePath.exists()) {
filePath.mkdir();
}
String target = dir + filename;
FileOutputStream outputStream = new FileOutputStream(target);
FileInputStream fileIn = new FileInputStream(file);
byte[] buffer = new byte[1024];
int len;
while ((len = fileIn.read(buffer)) > 0) {
outputStream.write(buffer, 0, len);
}
fileIn.close();
outputStream.close();
ret = true;
}
} catch (Exception ex) {
log.info("上传文件无法处理,请确认上传文件!");
}
return ret;
}
/**
* 下载文件
*
* @param file 上传文件实体
* @param filename 上传文件新命名
* @param dir 上传文件目录
* @return
*/
public Actionforward downloadFile(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
try{
response.reset();
response.setContentType("application/vnd.ms-excel"); //改成输出excel文件
response.setHeader("Content-disposition","attachment; filename="+execlName );
//新建以文件outputfile 为目标的输出文件流
OutputStream out = response.getOutputStream();;
//将工作簿写入输出文件流,得到输出报表文件
pd.exportExcel(out) ;
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace () ;
}
return null;
}
--------------------------------
删除文件:
/**
* 删除文件
*
* @param filePathAndName 删除文件完整路径:d:/filedir/filename
* @return
*/
public static boolean delFile(String filePathAndName) {
boolean ret = false;
try {
new File(filePathAndName.toString()).delete();
ret = true;
} catch (Exception e) {
System.out.println("删除文件操作出错");
e.printStackTrace();
}
return ret;
}
----------------------------------------
删除目录下全部文件:
/**
* 删除目录下的文件
*
* @param dir 文件目录 d:/filedir/
* @return
*/
public static boolean delFiles(String dir) {
boolean ret = false;
try {
File filePath = new File(dir);// 查询路径
String[] files = filePath.list();// 存放所有查询结果
int i = 0;
for (i = 0; i < files.length; i++) {
new java.io.File(dir + "/" + files[i]).delete();
}
ret = true;
} catch (Exception e) {
e.printStackTrace();
}
return ret;
}
--------------------------------------------
判断文件是否存在
/**
* 判断文件是否存在
*
* @param filename
* @return
*/
public static boolean isExist(String filename) {
boolean ret = false;
try {
File file = new File(filename.toString());
if (file.exists()) {
ret = true;
}
} catch (Exception e) {
e.printStackTrace();
}
return ret;
}
-------------------------------------------------
根据制定路径,可以获取当前正在操作的文件的大小,容量为byte.
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class FileByte {
private String filePath = "D:\\m07012600030000001_z.wav";
private void getFileByte(){
File f = new File(filePath) ;
try{
FileInputStream fis = new FileInputStream(f) ;
try {
System.out.println(fis.available()) ;
}catch(IOException e1){
e1.printStackTrace();
}
}catch(FileNotFoundException e2){
e2.printStackTrace();
}
}
public static void main(String[] args)
{
FileByte fb = new FileByte();
fb.getFileByte();
}
}
-------------------------------------------------------
如何用java获取网络文件的大小(多线程)
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
public class saveToFile {
public void saveToFile(String destUrl, String fileName) throws IOException
{
FileOutputStream fos = null;
BufferedInputStream bis = null;
HttpURLConnection httpUrl = null;
URL url = null;
byte[] buf = new byte[2];
int size = 0;
int s=0;
//建立链接
url = new URL(destUrl);
httpUrl = (HttpURLConnection) url.openConnection();
//连接指定的资源
httpUrl.connect();
//获取网络输入流
bis = new BufferedInputStream(httpUrl.getInputStream());
//建立文件
fos = new FileOutputStream(fileName);
System.out.println("正在获取链接[" + destUrl + "]的内容...\n将其保存为文件[" + fileName + "]");
//保存文件
while ( (size = bis.read(buf)) != -1)
{
fos.write(buf, 0, size);
//++s;
System.out.println(size);
//System.out.println(s/1024+"M");
}
fos.close();
bis.close();
httpUrl.disconnect();
}
//多线程文件下载程序:
public class DownloadNetTest {
private File fileOut;
private java.net.URL url;
private long fileLength=0;
//初始化线程数
private int ThreadNum=5;
public DownloadNetTest(){
try{
System.out.println("正在链接URL");
url=new URL("http://211.64.201.201/uploadfile/nyz.mp3");
HttpURLConnection urlcon=(HttpURLConnection)url.openConnection();
//根据响应获取文件大小
fileLength=urlcon.getContentLength();
if(urlcon.getResponseCode()>=400){
System.out.println("服务器响应错误");
System.exit(-1);
}
if(fileLength<=0)
System.out.println("无法获知文件大小");
//打印信息
printMIME(urlcon);
System.out.println("文件大小为"+fileLength/1024+"K");
//获取文件名
String trueurl=urlcon.getURL().toString();
String filename=trueurl.substring(trueurl.lastIndexOf('/')+1);
fileOut=new File("D://",filename);
}
catch(MalformedURLException e){
System.err.println(e);
}
catch(IOException e){
System.err.println(e);
}
init();
}
private void init(){
DownloadNetThread [] down=new DownloadNetThread[ThreadNum];
try {
for(int i=0;i<ThreadNum;i++){
RandomAccessFile randOut=new RandomAccessFile(fileOut,"rw");
randOut.setLength(fileLength);
long block=fileLength/ThreadNum+1;
randOut.seek(block*i);
down[i]=new DownloadNetThread(url,randOut,block,i+1);
down[i].setPriority(7);
down[i].start();
}
//循环判断是否下载完毕
boolean flag=true;
while (flag) {
Thread.sleep(500);
flag = false;
for (int i = 0; i < ThreadNum; i++)
if (!down[i].isFinished()) {
flag = true;
break;
}
}// end while
System.out.println("文件下载完毕,保存在"+fileOut.getPath() );
} catch (FileNotFoundException e) {
System.err.println(e);
e.printStackTrace();
}
catch(IOException e){
System.err.println(e);
e.printStackTrace();
}
catch (InterruptedException e) {
System.err.println(e);
}
}
private void printMIME(HttpURLConnection http){
for(int i=0;;i++){
String mine=http.getHeaderField(i);
if(mine==null)
return;
System.out.println(http.getHeaderFieldKey(i)+":"+mine);
}
}
//线程类
public class DownloadNetThread extends Thread{
private InputStream randIn;
private RandomAccessFile randOut;
private URL url;
private long block;
private int threadId=-1;
private boolean done=false;
public DownloadNetThread(URL url,RandomAccessFile out,long block,int threadId){
this.url=url;
this.randOut=out;
this.block=block;
this.threadId=threadId;
}
public void run(){
try{
HttpURLConnection http=(HttpURLConnection)url.openConnection();
http.setRequestProperty("Range","bytes="+block*(threadId-1)+"-");
randIn=http.getInputStream();
}
catch(IOException e){
System.err.println(e);
}
////////////////////////
byte [] buffer=new byte[1024];
int offset=0;
long localSize=0;
System.out.println("线程"+threadId+"开始下载");
try {
while ((offset = randIn.read(buffer)) != -1&&localSize<=block) {
randOut.write(buffer,0,offset);
localSize+=offset;
}
randOut.close();
randIn.close();
done=true;
System.out.println("线程"+threadId+"完成下载");
this.interrupt();
}
catch(Exception e){
System.err.println(e);
}
}
public boolean isFinished(){
return done;
}
}
}
}
----------------------------
pom.xml里面声明java的jar
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.6.0< ersion>
<scope>system</scope>
<systemPath>C:/Program Files/Java k1.6.0_05 b/tools.jar</systemPath>
</dependency>
----------------------------------------------
获取的路径里有空格变成20%以后,用什么把这个还原
String path = "111120%";
path=path.replace("20%"," ");
13795111413
----------------------------------------
70 到 110 之间怎么随机呢?
int ss=(int)(71+Math.random()*(100-71+1));
System.out.println(ss);
------------------------------------------
使用Calendar 处理时间格式
public static long parse(String dstr) {
if (dstr == null || dstr.length() == 0) {
return 0;
}
if (NumberUtils.isNumber(dstr)) {
return Long.parseLong(dstr) * 86400000;
}
String year = "";
String month = "";
String day = "";
int flag = 1;
char prech = 0;
dstr=dstr.trim();
for (char ch : dstr.toCharArray()) {
if (ch <= '9' && ch >= '0') {
switch (flag) {
case 1:
year += ch;
break;
case 2:
month += ch;
break;
case 3:
day += ch;
break;
}
} else {
if (prech <= '9' && prech >='0')
flag++;
}
prech = ch;
}
int y = year.equals("") ? 1970 : Integer.parseInt(year);
int m = month.equals("") ? 1 : Integer.parseInt(month);
int d = day.equals("") ? 1 : Integer.parseInt(day);
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, y);
cal.set(Calendar.MONTH, m-1);
cal.set(Calendar.DAY_OF_MONTH, d);
return cal.getTimeInMillis();
}
-------------------------------
输出任何格式的时间
截取时间
public void InterceptionTime() {
//先制造一个完整的时间.
DateFormat allTimeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
Date allTime = null;
try {
allTime = allTimeFormat.parse("2009-06-05 10:12:24.577");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//截取时间,也可以使用下边的SimpleDateFormat
DateFormat format = new SimpleDateFormat("HH:mm:ss.SSS");
String value = format.format(allTime);
System.out.println(value);
SimpleDateFormat dateFormat = new SimpleDateFormat ("yyyy-MM-dd");
String value2=dateFormat.format(allTime);
System.out.println(value2);
}
---------------------------------
转换2进制,
lang包中Integer类中有个static String toBinaryString(int i)
----------------------------------------------
oracle怎么判断表是否存在
select count(*) into num from USER_TABLES where TABLE_NAME='T2'
if num>0 then
--存在
end if;
------------------------------------------------------
记住帐号和密码
JS // 存cookie
Cookie user = new Cookie("User_Name", "hsyd");
Cookie pass = new Cookie("Password", "hsyd");
response.addCookie(user);
response.addCookie(pass);
// 取cookie
Cookie[] cookies = request.getCookies();
// ...找到匹配的cookie即可。
-----------------------------------------------------------------
相关推荐
IMG_20250415_160847.jpg
big_dripleaf_stem
内容概要:本文详细介绍了针对国内顶级科技公司(如华为、腾讯)的计算机求职面试内容与技巧。文章首先概述了技术能力考察的重点领域,包括数据结构与算法、操作系统、计算机网络、数据库以及特定编程语言的深入知识点。接着阐述了项目经验和系统设计方面的考察标准,强调了STAR法则的应用和具体的设计案例。此外,还分别描述了两家公司在面试流程上的不同之处,提供了具体的面试技巧,如代码编写的注意事项、项目回答的数据支持方法、系统设计的关键考量因素以及反问面试官的有效问题。最后,给出了避坑指南和资源推荐,帮助求职者更好地准备面试。 适合人群:即将或计划进入华为、腾讯等大型科技企业工作的应届毕业生和技术人员。 使用场景及目标:①帮助求职者了解并准备好技术面试所需的知识点;②指导求职者如何有效地展示自己的项目经验;③提供系统设计题目的解答思路;④传授面试过程中需要注意的行为规范和沟通技巧。 阅读建议:由于文中涉及大量专业知识和技术细节,建议读者在阅读时结合自身背景有选择地进行重点复习,并利用提供的资源链接进一步深化理解。同时,在准备过程中要注意将理论知识与实际操作相结合,多做练习以增强信心。
基于SpringBoot的课程设计选题管理系统,系统包含三种角色:管理员、用户,教师主要功能如下。 【用户功能】 系统首页:浏览课程设计选题管理系统的信息。 个人中心:管理个人信息,查看选题进展和历史记录。 课题信息管理:浏览已有的课题信息。 选题信息管理:查看已选择的选题信息。 自拟课题管理:提出和管理个人自拟的课题,。 系统管理:修改个人密码。 【管理员功能】 系统首页:查看系统整体概况。 个人中心:管理个人信息。 学生管理:审核和管理注册学生用户的信息。 教师管理:审核和管理注册教师用户的信息。 课题信息管理:监管和管理系统中的课题信息,包括发布、编辑、删除等。 课题分类管理:管理课题的分类信息。 选题信息管理:查看学生已选题目的情况,包括审批和管理选题流程。 自拟课题管理:审批和管理学生提出的自拟课题。 系统管理:管理系统的基本设置。 【教师功能】 系统首页:查看系统。 个人中心:管理个人信息。 课题信息管理:浏览已有的课题信息。 课题分类管理:管理课题的分类信息。 选题信息管理:查看学生已选题目的情况。 自拟课题管理:提出和管理个人自拟的课题。 系统管理:校园资讯管理。
橡胶履带牵引车辆改进设计(无极自动变速器方案设计).rar
剑桥大学发布的GVAR(Global Vector Autoregressive)数据集是用于全球宏观经济分析的重要社科数据资源。该数据集基于GVAR模型开发,旨在量化宏观经济发展对金融机构的影响,并分析全球经济互动。GVAR模型通过处理高维系统中的相互作用,解决了“维度诅咒”问题,适用于国家、地区、行业等多层次的经济分析。数据集包含1979-2016年33个国家的季度数据,可用于冲击情景分析、预测及政策评估。配套的GVAR工具箱(GVAR Toolbox)提供了用户友好的界面,支持MATLAB和Excel操作,便于研究人员开展实际应用。该数据集为经济学、金融学及相关领域的学术研究和政策制定提供了有力支持。
某汽车联合车间工艺布置图.zip
在stm32f407zgt上通过标准库实现w5500tcpserver和client,可以ping通速率不快
基于Python的微信跳一跳游戏程序
j
ElectLines.py
内容概要:本文档是一份针对Python测试开发工程师的算法能力测试卷,涵盖选择题、填空题、编程题和综合题四个部分。选择题考察Python基础知识、数据结构与算法、HTTP协议等;填空题涉及递归、排序、设计模式、HTTP请求方法、测试框架等具体知识点;编程题要求完成字符串反转、链表环检测、二叉树最大深度、两数之和及单元测试类的编写;综合题则包括设计自动化测试框架和实现测试报告生成器,旨在评估考生对Python编程和测试开发的全面掌握程度。 适合人群:具备Python编程基础,从事或计划从事测试开发工作的工程师。 使用场景及目标:①作为招聘流程中的技术考核工具;②帮助工程师自测和提升Python测试开发技能;③为企业内部培训提供标准化的评测标准。 阅读建议:此测试卷不仅考察语法和算法,更注重实际编程能力和解决问题的思路。建议考生在准备过程中多动手实践,熟悉常见的算法和数据结构,并掌握常用的测试框架和工具,如pytest、coverage等。同时,理解每个题目背后的设计意图,有助于更好地应对实际工作中的挑战。
一级减速器成套CAD图【22CAD】.rar
beetroots_stage2
IMG_20250415_104619.jpg
吴萌2262040206.zip
Android开发banner效果,用的是youthbanner的库,你们也可以去找原库demo
该资源为h5py-3.13.0-cp310-cp310-win_amd64.whl,欢迎下载使用哦!
内容概要:本文档提供了一个基于Python的贪吃蛇游戏完整代码示例。代码主要使用了Pygame库来创建游戏窗口、处理图形渲染与事件响应。游戏规则简单明了:玩家控制一条绿色的小蛇在黑色背景的游戏区域内移动,通过键盘方向键改变小蛇行进的方向,目的是吃到红色的食物方块使自身变长。当小蛇碰到边界或者自己的身体时,则判定为游戏失败并提示玩家选择是否重新开始或退出游戏。此外,还设置了帧率限制确保游戏流畅度。 适合人群:有一定Python编程基础的学习者,特别是对Pygame库感兴趣的开发者。 使用场景及目标:①作为初学者练习项目,帮助理解Pygame的基本用法;②可用于教学演示,讲解面向对象编程思想以及事件驱动机制;③为后续开发更复杂的游戏打下良好基础。 阅读建议:建议先熟悉Python语言特性及基本语法,再逐步深入研究本代码中的各个函数功能及其调用关系。同时可以尝试修改参数值(如窗口尺寸、颜色配置等),观察不同设置下的效果变化,从而加深对整个程序的理解。
birch_planks