我正在尝试从Windows中的命令行执行Java程序.这是我的代码:
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class CopyFile
{
public static void main(String[] args)
{
InputStream inStream = null;
OutputStream outStream = null;
try
{
File afile = new File("input.txt");
File bfile = new File("inputCopy.txt");
inStream = new FileInputStream(afile);
outStream = new FileOutputStream(bfile);
byte[] buffer = new byte[1024];
int length;
// copy the file content in bytes
while ((length = inStream.read(buffer)) > 0)
{
outStream.write(buffer, 0, length);
}
inStream.close();
outStream.close();
System.out.println("File is …Run Code Online (Sandbox Code Playgroud) 所以我想弄明白这一点.我做了一个名字的arraylist年龄必须按年龄,然后按名称排序(如果年龄相等)我确信有一个简单的方法来做到这一点,但我们的教训是要求我们使用接口.所以我到目前为止的是一个人名和年龄的数组列表,然后是一个人类,我可以从中检索信息.如何对要传递回主类的列表进行排序?PersonSorter:
import java.util.ArrayList;
import java.util.Collections;
public class PersonSorter
{
public static void main(String[] args)
{
ArrayList<Person> people = new ArrayList<Person>();
people.add(new Person("Linda", 63));
people.add(new Person("Jacob", 5));
people.add(new Person("Emily", 13));
people.add(new Person("Jessica", 21));
people.add(new Person("Emma", 5));
people.add(new Person("Robert", 80));
people.add(new Person("Jennifer", 43));
// PRINT THE LIST OF PEOPLE BEFORE SORTING
for (Person person : people)
{
System.out.println(person);
}
System.out.println();//space between the lists
Collections.sort(people);
// PRINT THE LIST OF PEOPLE AFTER SORTING
for (Person person : people)
{
System.out.println(person);
}
}
} …Run Code Online (Sandbox Code Playgroud) java ×2