首页 > 编程知识 正文

java时间字符串当文件名,java 当前时间字符串

时间:2023-12-27 22:26:02 阅读:323463 作者:TNIH

本文目录一览:

java 通过字符串获取文件名

如果unistat/ 文件都在这个路径下可以写为

subString(url.indexOf(”unistat/“)+8,url.indexOf(”.jsp“)+4);

java 字符串存为文件

很简单啊,new一个文件,然后写入新建的文件中,新建的文件名后缀用doc就行了

java 用系统时间做文件的保存名称

SimpleDateFormat  si=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");

///获得当前系统时间  年-月-日 时:分:秒

String time=si.format(new Date());

//将时间拼接在文件名上即可

java 字符串(文件名),得到文件格式字符串

public class FindType {

public static void main(String[] args) {

String s1 = "20151012.mp4";

System.out.println(getType(s1));//.mp4

String s2 = "123.007.txt";//假设文件名有很多的点也可以

System.out.println(getType(s2));//.txt

}

//方法去寻找最后一个点开头的字符串

static String getType(String s){

String[] ss = s.split("\.");//表示用.去切割字符串

return "."+ss[ss.length-1];//用.连接最后一个字符串 

}

}

输出

.mp4

.txt

java输出系统时刻并且输入到一个文件里

Date now = new Date();

SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

String text = format.format(now);

/**

* 将字符串写到文件中去

* @param fileName 文件名

* @param text 文本

*/

public static void write(String fileName, String text) {

try {

PrintWriter out = new PrintWriter(new File(fileName).getAbsoluteFile());

try {

out.print(text);

} finally {

out.close();

}

} catch (IOException e) {

throw new RuntimeException(e.getMessage());

}

}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。