笑傲Java面试:面霸修炼手册

V:ititit111222333

package com.tarzan.recommend.Service;import com.tarzan.recommend.dto.ItemDTO;import com.tarzan.recommend.dto.RelateDTO;import com.tarzan.recommend.dto.UserDTO;import lombok.Data;import lombok.extern.slf4j.Slf4j;import org.assertj.core.util.Lists;import org.springframework.util.ResourceUtils;import java.io.*;import java.nio.charset.StandardCharsets;import java.util.List;@Data@Slf4jpublic class FileDataSource {      public final static String folderPath="F:\\ml-100k";    /**     * 方法描述: 读取基础数据     *     * @param     * @Return {@link List< RelateDTO>}     * @throws     * @author tarzan     * @date 2020年07月31日 16:53:40     */    public static List<RelateDTO> getData() {        List<RelateDTO> relateList = Lists.newArrayList();        try {            FileInputStream out = new FileInputStream(folderPath+"\\u.data");            InputStreamReader reader = new InputStreamReader(out, StandardCharsets.UTF_8);            BufferedReader in = new BufferedReader(reader);            String line = null;            while ((line = in.readLine()) != null) {                String newline = line.replaceAll("[\t]", " ");                String[] ht = newline.split(" ");                Integer userId = Integer.parseInt(ht[0]);                Integer movieId = Integer.parseInt(ht[1]);                Integer rating = Integer.parseInt(ht[2]);                RelateDTO dto = new RelateDTO(userId, movieId, rating);                relateList.add(dto);            }        } catch (IOException e) {            log.error(e.getMessage());        }        return relateList;    }    /**     * 方法描述: 读取用户数据     *     * @param     * @Return {@link List< UserDTO>}     * @throws     * @author tarzan     * @date 2020年07月31日 16:54:51     */    public static List<UserDTO> getUserData() {        List<UserDTO> userList = Lists.newArrayList();        try {            FileInputStream out = new FileInputStream(folderPath+"\\u.user");            InputStreamReader reader = new InputStreamReader(out, StandardCharsets.UTF_8);            BufferedReader in = new BufferedReader(reader);            String line = null;            while ((line = in.readLine()) != null) {                String newline = line.replaceAll("[\t]", " ");                String[] ht = newline.split("\\|");                Integer id = Integer.parseInt(ht[0]);                Integer age = Integer.parseInt(ht[1]);                String sex = ht[2];                String profession = ht[3];                String postcode = ht[4];                UserDTO dto = new UserDTO(id, age, sex, profession, postcode);                userList.add(dto);            }        } catch (IOException e) {            log.error(e.getMessage());        }        return userList;    }    /**     * 方法描述: 读取电影数据     *     * @param     * @Return {@link List< ItemDTO>}     * @throws     * @author tarzan     * @date 2020年07月31日 16:54:22     */    public static List<ItemDTO> getItemData() {        List<ItemDTO> itemList = Lists.newArrayList();        try {            FileInputStream out = new FileInputStream(folderPath+"\\u.item");            InputStreamReader reader = new InputStreamReader(out, StandardCharsets.UTF_8);            BufferedReader in = new BufferedReader(reader);            String line = null;            while ((line = in.readLine()) != null) {                String newline = line.replaceAll("[\t]", " ");                String[] ht = newline.split("\\|");                Integer id = Integer.parseInt(ht[0]);                String name = ht[1];                String date = ht[2];                String link = ht[3];                ItemDTO dto = new ItemDTO(id, name, date, link);                itemList.add(dto);            }        } catch (IOException e) {            log.error(e.getMessage());        }        return itemList;    }}


©著作权归作者所有:来自51CTO博客作者mb5fdf56b9cf058的原创作品,如需转载,请注明出处,否则将追究法律责任

更多相关文章

  1. Mybatis【2.1】-- 从读取流到创建SqlSession发生了什么?
  2. 位置不可用无法访问磁盘结构损坏且无法读取 chkdsk无法修复. 不
  3. 如何从io.Reader 中读数据
  4. linux系统执行读取jar包同级目录的外部配置文件
  5. 循环单链表及常用操作(C语言描述)
  6. Spark Core读取ES的分区问题分析
  7. Unity3D直接从Zip中读取文本数据
  8. 当年pass到很多扒手的题
  9. 嵌入式开发,各类存储方式知多少?

随机推荐

  1. 简述修改logo以及文字
  2. Android系统自带主题样式(android:theme),An
  3. Android界面——LinearLayout和RelativeL
  4. RelativeLayout 常用XML 属性
  5. android Wifi自动连接
  6. Android使用ViewFlipper做页面切换,与手势
  7. Android发展史
  8. 写一个没有Activity的 HelloWorld for an
  9. 通过xml加载菜单Menus
  10. Android图形系统分析与移植--五、Android