package com;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.RandomAccessFile;
public class Preprocess {
public static void appendMethodA(String fileName,
String content){
try {
// 打开一个随机访问文件流,按读写方式
RandomAccessFile randomFile = new RandomAccessFile(fileName, "rw");
// 文件长度,字节数
long fileLength = randomFile.length();
//将写文件指针移到文件尾。
randomFile.seek(fileLength);
randomFile.writeBytes(content);
randomFile.close();
} catch (IOException e){
e.printStackTrace();
}
}
public static void readFileByLines(String fileName){
File file = new File(fileName);
BufferedReader reader = null;
try {
System.out.println("以行为单位读取文件内容,一次读一整行:");
reader = new BufferedReader(new FileReader(file));
String tempString = null;
int line = 1;
//一次读入一行,直到读入null为文件结束
while ((tempString = reader.readLine()) != null){
//显示行号
//System.out.println("line " + line + ": " + tempString);
//line++;
//写入到文件中
String filename = "out.txt";
String[] strarr = tempString.split("::");
String deststr = strarr[0]+","+strarr[1]+","+strarr[2]+"\n";
appendMethodA(filename,deststr);
}
reader.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null){
try {
reader.close();
} catch (IOException e1) {
}
}
}
}
public static void main(String[] args) throws Exception{
//FileReader fr = new FileReader("ratings.dat");
readFileByLines("ratings.dat");
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
基于Mahout的电影推荐系统,数据预处理程序源码,程序处理rating.dat文件.zip (5个子文件)
PreProcessDataRecommender-master
.classpath 301B
.settings
org.eclipse.jdt.core.prefs 598B
src
com
Preprocess.java 2KB
bin
com
Preprocess.class 2KB
.project 401B
共 5 条
- 1
资源评论
博士僧小星
- 粉丝: 1746
- 资源: 5850
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功