请教两道java编程题,关于IO包的。
来源:百度知道 编辑:UC知道 时间:2024/06/01 14:14:54
2,用nio包实现上题。
希望结果能够直接运行成功,不胜感激!如果直接通过,会有加分。
package com;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class Point {
public static void main(String[] args) {
Point p = new Point();
String path = "";// 你要读取的文件的路径 @example@
// "D:\\workspace\\JavaTest\\bin\\com\\a.txt"
p.outputMethod(path);
}
public void outputMethod(String path) {
try {
String[] arr = new String[1];
String[] temp;
BufferedReader br = new BufferedReader(new FileReader(path));
String line = br.readLine();
while (line != null) {
arr[arr.length-1] = line;
temp = new String[arr.length+1];
for(int i=0;i<arr.length;i++){
temp[i] = arr[i];
}
arr = new String[temp.length];
for(int i=0;i<arr.length;i++){