package fd;import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Iterator;public class MyTest {
// 读取文件方法
public ArrayList readfile(String path) // 从文本文件中读取内容
{
String read = null;
String strx = null;
ArrayList list = new ArrayList();
try {
String filepath = path; // 得到文本文件的路径
File file = new File(filepath);
if (file.exists()) { // 判断文件路径是否正确
FileReader fileread = new FileReader(file);
BufferedReader bufread = new BufferedReader(fileread);
boolean found = false;
while ((read = bufread.readLine()) != null) {
if (!found) {
if (read.indexOf("SZ") != -1) {
found = true;
} else {
continue;
}
}
strx = read.substring(47, 65);
list.add(strx); }
} else {
System.out.println("文件路径不对!");
}
} catch (Exception d) {
System.out.println(d.getMessage());
} return list; // 返回从文本文件中读取内容
} public static void main(String args[]) {
MyTest test = new MyTest();
ArrayList s = test.readfile("E:/xm/Z02ZI268/Z02ZI268/Z02ZI268.s");
Iterator it = s.iterator();
while (it.hasNext()) {
String ss = String.valueOf(it.next());
System.out.println(ss); } }
}
我从文件里读出来的数据放到了,ArrayList里,我想取出放在INT数组里,目的是想判断最大值和最小值,请问该怎么做啊~
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Iterator;public class MyTest {
// 读取文件方法
public ArrayList readfile(String path) // 从文本文件中读取内容
{
String read = null;
String strx = null;
ArrayList list = new ArrayList();
try {
String filepath = path; // 得到文本文件的路径
File file = new File(filepath);
if (file.exists()) { // 判断文件路径是否正确
FileReader fileread = new FileReader(file);
BufferedReader bufread = new BufferedReader(fileread);
boolean found = false;
while ((read = bufread.readLine()) != null) {
if (!found) {
if (read.indexOf("SZ") != -1) {
found = true;
} else {
continue;
}
}
strx = read.substring(47, 65);
list.add(strx); }
} else {
System.out.println("文件路径不对!");
}
} catch (Exception d) {
System.out.println(d.getMessage());
} return list; // 返回从文本文件中读取内容
} public static void main(String args[]) {
MyTest test = new MyTest();
ArrayList s = test.readfile("E:/xm/Z02ZI268/Z02ZI268/Z02ZI268.s");
Iterator it = s.iterator();
while (it.hasNext()) {
String ss = String.valueOf(it.next());
System.out.println(ss); } }
}
我从文件里读出来的数据放到了,ArrayList里,我想取出放在INT数组里,目的是想判断最大值和最小值,请问该怎么做啊~
实例如下:public class Main {
public static void main(String[] args) {
List<Integer> arr = new ArrayList<Integer>();
arr.add(3);
arr.add(8);
arr.add(23);
arr.add(67);
arr.add(5);
Collections.sort(arr);
System.out.println(arr);
}
}
//--------------------------------------
打印出[3, 5, 8, 23, 67]排序后的数组