关于javalrc的信息

博主:adminadmin 2023-01-10 13:54:08 951

今天给各位分享javalrc的知识,其中也会对进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

在java中怎么从键盘输入一段歌词以空格用split()分割

public static void main(String[] args) {

// TODO 自动生成的方法存根

Scanner sc = new Scanner(System.in);

System.out.println("请输入歌词:");

String s = sc.nextLine();

String[] x = s.split(" ");

for(int i = 0;ix.length;i++){

System.out.println(x[i]);

}

}

java解析lrc文件代码

lrc可以通过如下util工具类进行转换,如果想知道结果是否读取的有问题,可以直接用记事本打开lrc文件的,之后和输出结果比对一下就行。

package com.routon.utils;

import java.io.BufferedReader;

import java.io.FileInputStream;

import java.io.IOException;

import java.io.InputStreamReader;

import java.util.ArrayList;

import java.util.List;

import java.util.regex.Matcher;

import java.util.regex.Pattern;

import android.util.Log;

/**

* parse lrc file tool

* eg:

* utilLrc lrc = new utilLrc("/sdcard/test.lrc");

* get song name : String title = lrc.getTitle();

* get performer name : String artist = lrc.getArtist();

* get album name: String album = lrc.getAlbum();

* get lrcmaker name: String lrcMaker = lrc.getLrcMaker();

* get song list: ListStatement list = lrc.getLrcList();

*

* @author xuweilin

*

*/

public class utilLrc {

private static String TAG = "utilLrc";

public class Statement {

private double time = 0.0; //time, 0.01s

private String lyric = ""; //song word

/*

* get time

*/

public double getTime() {

return time;

}

/*

* set time

*/

public void setTime(double time) {

this.time = time;

}

/*

* set time.format:mm:ss.ms

*/

public void setTime(String time) {

String str[] = time.split(":|\\.");

this.time = Integer.parseInt(str[0])*60+Integer.parseInt(str[1])+Integer.parseInt(str[2])*0.01;

}

/*

* get lrc word

*/

public String getLyric() {

return lyric;

}

/*

* set lrc word

*/

public void setLyric(String lyric) {

this.lyric = lyric;

}

}

private BufferedReader bufferReader = null;

private String title = "";

private String artist = "";

private String album = "";

private String lrcMaker = "";

private ListStatement statements = new ArrayListStatement();

/*

*

* fileName

*/

public utilLrc(String fileName) throws IOException{

FileInputStream file = new FileInputStream(fileName);

bufferReader = new BufferedReader(new InputStreamReader(file, "utf-8"));

readData();

}

/*

* read the file

*/

private void readData() throws IOException{

statements.clear();

String strLine;

while(null != (strLine = bufferReader.readLine()))

{

if("".equals(strLine.trim()))

{

continue;

}

if(null == title || "".equals(title.trim()))

{

Pattern pattern = Pattern.compile("\\[ti:(.+?)\\]");

Matcher matcher = pattern.matcher(strLine);

if(matcher.find())

{

title=matcher.group(1);

continue;

}

}

if(null == artist || "".equals(artist.trim()))

{

Pattern pattern = Pattern.compile("\\[ar:(.+?)\\]");

Matcher matcher = pattern.matcher(strLine);

if(matcher.find())

{

artist=matcher.group(1);

continue;

}

}

if(null == album || "".equals(album.trim()))

{

Pattern pattern = Pattern.compile("\\[al:(.+?)\\]");

Matcher matcher = pattern.matcher(strLine);

if(matcher.find())

{

album=matcher.group(1);

continue;

}

}

if(null == lrcMaker || "".equals(lrcMaker.trim()))

{

Pattern pattern = Pattern.compile("\\[by:(.+?)\\]");

Matcher matcher = pattern.matcher(strLine);

if(matcher.find())

{

lrcMaker=matcher.group(1);

continue;

}

}

int timeNum=0;

String str[] = strLine.split("\\]");

for(int i=0; istr.length; ++i)

{

String str2[] = str[i].split("\\[");

str[i] = str2[str2.length-1];

if(isTime(str[i])){

++timeNum;

}

}

for(int i=0; itimeNum;++i)

{

Statement sm = new Statement();

sm.setTime(str[i]);

if(timeNumstr.length)

{

sm.setLyric(str[str.length-1]);

}

statements.add(sm);

}

}

sortLyric();

}

/*

* judge the string is or not date format.

*/

private boolean isTime(String string)

{

String str[] = string.split(":|\\.");

if(3!=str.length)

{

return false;

}

try{

for(int i=0;istr.length;++i)

{

Integer.parseInt(str[i]);

}

}

catch(NumberFormatException e)

{

Log.e(TAG, "isTime exception:"+e.getMessage());

return false;

}

return true;

}

/*

* sort the word by time.

*/

private void sortLyric()

{

for(int i=0;istatements.size()-1;++i)

{

int index=i;

double delta=Double.MAX_VALUE;

boolean moveFlag = false;

for(int j=i+1;jstatements.size();++j)

{

double sub;

if(0=(sub=statements.get(i).getTime()-statements.get(j).getTime()))

{

continue;

}

moveFlag=true;

if(subdelta)

{

delta=sub;

index=j+1;

}

}

if(moveFlag)

{

statements.add(index, statements.get(i));

statements.remove(i);

--i;

}

}

}

/**

* get title

* @return

*/

public String getTitle(){

return title;

}

/**

* get artist

* @return

*/

public String getArtist(){

return artist;

}

/**

* get album

* @return

*/

public String getAlbum(){

return album;

}

/**

* get lrc maker

* @return

*/

public String getLrcMaker(){

return lrcMaker;

}

/**

* get song list

* @return

*/

public ListStatement getLrcList(){

return statements;

}

}

java程序 做一个这样的程序:统计某磁盘的使用情况 统计在这磁盘中,各种文件的个数和占磁盘空间

import java.io.File;

import java.io.FileFilter;

import java.util.HashMap;

import java.util.Map;

public class T1 {

    /**存放文件后缀 对应的大小*/

    private static final MapString, Long sizeMap = new HashMapString, Long();

    /**存放文件后缀 对应的个数*/

    private static final MapString, Integer countMap = new HashMapString, Integer();

    

    

    public static void main(String[] args) {

        String path = "F:";

        filter(path);

        

        for(String key :sizeMap.keySet()) {

            System.out.println("后缀:" + key + "\t字节:" + (sizeMap.get(key)==null?0:sizeMap.get(key)) + "\t个数为" + (countMap.get(key)==null?0:countMap.get(key)));

        }

        

    }

    

    

    public static void filter(String path){

        File file = new File(path);

        file.listFiles(new FileFilter() {

            @Override

            public boolean accept(File f) {

                if(f.isDirectory()) {

                    filter(f.getPath());

                    return false;

                }

                String fileName = f.getName();

                

                if(fileName.indexOf(".") == -1) {

                    return false;

                }

                

                String suffix =fileName.split("\\.")[1];//获得文件后缀

                //把文件后缀相同的字节数相加

                Long size = (sizeMap.get(suffix)==null?0:sizeMap.get(suffix)) + f.length();

                sizeMap.put(suffix, size);

                //把文件后缀相同的个数相加

                Integer count = (countMap.get(suffix)==null?0:countMap.get(suffix)) + 1;            

                countMap.put(suffix, count);

                return false;

            }

        });

    }

}

运行结果太长了,我随便截取点吧:

后缀:1-1    字节:1820    个数为2

后缀:dll_2016-05-23_000    字节:345    个数为1

后缀:dat    字节:20253796    个数为28

后缀:1-2    字节:1302    个数为2

后缀:md    字节:53548    个数为4

后缀:MF    字节:1105    个数为10

后缀:html    字节:745985    个数为75

后缀:lrc    字节:6872    个数为6

后缀:9-2    字节:1478    个数为2

后缀:dll_2016-03-31_000    字节:55    个数为1

后缀:9-3    字节:1436    个数为2

后缀:all    字节:3003366    个数为4

后缀:66b    字节:6786365    个数为1

后缀:withoutimage    字节:383536    个数为4

后缀:eclipse    字节:27666    个数为104

后缀:woff    字节:437588    个数为20

后缀:spr    字节:15084930    个数为311

后缀:mdl    字节:79521996    个数为487

后缀:m3d    字节:199680    个数为3

后缀:JPG    字节:261216    个数为113

后缀:fgd    字节:37819    个数为1

后缀:79d    字节:23795338    个数为3

后缀:79e    字节:8001129    个数为1

后缀:gif    字节:1453085    个数为597

后缀:dll_2016-04-26_000    字节:115    个数为1

后缀:70LeagueV    字节:549361    个数为1

后缀:lst    字节:47492    个数为13

后缀:26q_v1    字节:7284946    个数为1

后缀:sql    字节:87909    个数为6

后缀:11-4    字节:1230    个数为2

后缀:11-3    字节:1804    个数为2

后缀:timer    字节:10452    个数为3

后缀:html5only    字节:467448    个数为4

后缀:dll_2016-05-17_000    字节:115    个数为1

后缀:11-2    字节:1770    个数为2

后缀:11-1    字节:2032    个数为2

后缀:flexslider-min    字节:65025    个数为3

后缀:dll_2016-07-01_000    字节:13427    个数为2

后缀:greenxf    字节:97562    个数为1

特地敲了代码 要采纳啊,我这测试的是F盘 是可以的, 你有什么疑问  可追问我

请用java编程:

import java.io.BufferedReader;

import java.io.BufferedWriter;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.InputStreamReader;

import java.io.OutputStreamWriter;

public class Lyric2Text {

 

 public void doWork(String lyric) throws IOException{

  BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(lyric), "utf8"));

  BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(lyric.substring(0, lyric.lastIndexOf('.')) + ".txt"), "utf8"));

  String line;

  while((line = reader.readLine()) != null){

   line = line.replaceAll("\\[[0-9:\\.]+\\]", "");

   writer.write(line + "\n");

  }

  

  reader.close();

  writer.close();

 }

 

 public static void main(String[] args) throws IOException {

  Lyric2Text tmp = new Lyric2Text();

  tmp.doWork("C:\\Users\\admin\\Desktop\\一帘幽梦.lrc");

 }

}

求教,急用!JAVA按歌词文件的时间标签从小到大排列内容,然后最好能给我做个方法,让我直接调用,排

你好,这是你要的方法,直接输入路径调用就可以了,输出结果是sorted-加原文件名

/**

 * 根据路径和编码 重新排列歌词中的文件,转换后的文件是“sorted-原文件”

 *

 * @param source 原文件

 */

public static void sortLyric(String source) {

    try {

        BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(source), "UTF-8"));

        ListString lines = new ArrayListString();

        String line;

        while ((line = br.readLine()) != null) {

            lines.add(line);

        }

        br.close();

        Collections.sort(lines);

        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("sorted-" + source, false), "UTF-8"));

        for (String everyLine : lines) {

            bw.write(everyLine);

            bw.newLine();

            bw.flush();

        }

        bw.close();

    } catch (Exception e) {

        e.printStackTrace();

    }

}

javalrc的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于、javalrc的信息别忘了在本站进行查找喔。