又是你啊 ,上午已经回答了你一个问题了。你的编码格式设置下 就可以了。
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.RandomAccessFile;
public class Random {
public static void main(String[] args) throws Exception {
int lineCount = 0;
File f = new File("E:\\数学3班.txt");
RandomAccessFile raf = new RandomAccessFile(f, "r");
java.util.Random r1 = new java.util.Random();
BufferedReader buffer = new BufferedReader(new InputStreamReader(
new FileInputStream(f)));
while (buffer.readLine() != null) {
lineCount++;
}
int a = r1.nextInt(lineCount);
int i = 0;
while (raf.readLine() != null) {
i++;
if (i == a) {
String temp = raf.readLine();
System.out
.println(new String(temp.getBytes("iso8859-1"), "GBK"));
}
}
}
}
这一行,
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("")), "UTF-8"));将编码格式改成你写txt所用的编码格式...
在读取的时候把编码格式改了,就好了
最好不要中文路径