import java.io.FileNotFoundException
import java.io.IOException
import java.io.RandomAccessFile
import java.util.ArrayList
public class ShowSourceCode {
public static void main(String[] args) throws FileNotFoundException, IOException{
RandomAccessFile file = new RandomAccessFile("Add.java", "r")
String tmp
while((tmp = file.readLine()) != null){
System.out.println(tmp)
}
file.seek(0)
int lineNum = 1
while((tmp = file.readLine()) != null){
System.out.println(lineNum + ": " + tmp)
lineNum++
}
}
}
文件名换成你自己即可import java.io.FileNotFoundException
import java.io.IOException
import java.io.RandomAccessFile
import java.util.ArrayList
public class ShowSourceCode {
public static void main(String[] args) throws FileNotFoundException, IOException{
RandomAccessFile file = new RandomAccessFile("Add.java", "r")
String tmp
while((tmp = file.readLine()) != null){
System.out.println(tmp)
}
file.seek(0)
int lineNum = 1
while((tmp = file.readLine()) != null){
System.out.println(lineNum + ": " + tmp)
lineNum++
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)