我希望我应该使用文件输入流从文本文件中读取一些文本..然后使用 set 或 get 方法存储这些数据..现在使用 arraylist 对这些数据进行排序......
类 SongDetail 将用于设置歌曲、电影名和艺术家的值....有一个文本文件“text1.txt”存储了歌曲/电影名/艺术家的详细信息......现在我想要在我读到这个文件时Class1,String reurned 将被拆分为 song,movieName,artist,这是在 songDetail 类中设置的。
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.*;
public class Class1 {
public static void main(String[] args) {
//ArrayList <String>list = new ArrayList<String>();
ArrayList <String>list = new ArrayList<String>();
try
{
FileInputStream in = new FileInputStream("text1.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
while((strLine = br.readLine())!= null)
{
// System.out.println(strLine);
list.add(strLine);
//System.out.print(list);
}
System.out.print(list);
Collections.sort(list);
}catch(Exception e){
System.out.println(e);
}
}
}
class SongDetail
{
private String song;
private String movieName;
private String artist;
public SongDetail
{
}
public void setSong(String song) throws InvalidSongException
{
this.song=song;
{
throw new InvalidSongException();
} }
public void setMovieName(String movieName)
{
this.movieName=movieName;
}
public void setArtist(String artist) throws InvalidArtistException
{
this.artist=artist;
{
throw new InvalidMarkException();
}
}
public String getSong()
{
return song;
}
public String getMovieName()
{
return movieName;
}
public String getArtist()
{
return artist;
}
}