简体   繁体   English

java 字符串 function 需要帮助

[英]java string function need help

System.out.println(s.toString().substring(0,s.indexOf(".mp3")));

i am downloading file from android application..我正在从 android 应用程序下载文件..
i need to name them as 1 2 3 like that.. so.. i'll need to do is increment the max size of it so i've done the我需要像这样将它们命名为 1 2 3.. 所以.. 我需要做的是增加它的最大大小,所以我已经完成了

System.out.println(s.toString().substring(0,s.indexOf(".mp3")));

from this it will give me 1 2 3 that is spite my mp3 file name now i want to fine max of it so i can increment it by 1 but how to do this?从此它会给我 1 2 3 ,尽管我的 mp3 文件名现在我想将它的最大值很好,所以我可以将它增加 1 但如何做到这一点?

Well, you could parse each filename (eg using Integer.parseInt ).好吧,您可以解析每个文件名(例如,使用Integer.parseInt )。

Alternatively, if you knew you'd have less than (say) 100,000 files, you could format the filenames in a sortable fashion to start with - so instead of 141.mp3, you'd have 00141.mp3.或者,如果您知道您将拥有少于(例如)100,000 个文件,您可以以可排序的方式格式化文件名 - 因此您将拥有 00141.mp3 而不是 141.mp3。 That way you could just sort all the filenames and parse the last one.这样你就可以对所有文件名进行排序并解析最后一个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM