- hintcnuie
- 等级:
![一星会员 一星会员](/images/star1.gif)
![hintcnuie的博客: hintcnuie hintcnuie的博客](https://www.iteye.com/upload/logo/user/17768/0f30c998-0ed7-365a-ab75-77111c848148.jpg?1717537352)
- 性别:
![男](/images/icon_minigender_1.gif) - 文章: 60
- 积分: 137
- 来自: 北京
![](/images/status/offline.gif)
|
主要逻辑是从txt文件中抽取词:
- artists = new HashMap();
- InputStream is = this.getClass().getClassLoader().getResourceAsStream("org/richfaces/demo/tree/data.txt");
- ByteArrayOutputStream os = new ByteArrayOutputStream();
- byte[] rb = new byte[1024];
- int read;
- try {
- do {
- read = is.read(rb);
- if (read>0) {
- os.write(rb, 0, read);
- }
- } while (read>0);
- String buf = os.toString();
- StringTokenizer toc1 = new StringTokenizer(buf,"\n");
- while (toc1.hasMoreTokens()) {
- String str = toc1.nextToken();
- StringTokenizer toc2 = new StringTokenizer(str, "\t");
- String songTitle = toc2.nextToken();
- String artistName = toc2.nextToken();
- String albumTitle = toc2.nextToken();
- toc2.nextToken();
- toc2.nextToken();
- String albumYear = toc2.nextToken();
- Artist artist = getArtistByName(artistName,this);
- Album album = getAlbumByTitle(albumTitle, artist);
- album.setYear(new Integer(albumYear));
- Song song = new Song(getNextId());
- song.setTitle(songTitle);
- album.addSong(song);
- }
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
txt文件见附件。
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
|
返回顶楼 |
|
|