在下有一小题,运行出错,请帮忙。谢谢阿!
import java.io.*;
import java.util.*;
class Tail
{
public static void main(String args[]) throws IOException
{
if (args[].length==0)
System.out.println("File not exit!");
else
for (int i=0;i<args.length;i++)
{
File f;
f=new File(args[i]);
BufferedReader in=new BufferedReader (new FileReader(f));
Array List al=new Array List ();
while (true)
{
al.add(in.readLine());
if (f.available()==0)
{String str1[]=new String [al.length()];
str1=al.toArray(str1);
for (int i=str.length-10;i<str1.length;i++ )
{System.out,println(str1[i]);}
break;
}
}
}
}
}
//编写一程序,打印命令行指定的文件的最后10
import java.io.*;
import java.util.*;
class Tail
{
public static void main(String args[]) throws IOException
{
if (args[].length==0)
System.out.println("File not exit!");
else
for (int i=0;i<args.length;i++)
{
File f;
f=new File(args[i]);
BufferedReader in=new BufferedReader (new FileReader(f));
Array List al=new Array List ();
while (true)
{
al.add(in.readLine());
if (f.available()==0)
{String str1[]=new String [al.length()];
str1=al.toArray(str1);
for (int i=str.length-10;i<str1.length;i++ )
{System.out,println(str1[i]);}
break;
}
}
}
}
}
//编写一程序,打印命令行指定的文件的最后10
解决方案 »
- 如何对一个字符串按逗号和分号分割成数组
- 捕获输出流
- jdom element.setAttribute("xmlns","....");,为啥不能创建?
- 求解 扫面线算法画不出来啊!!!
- java抽象类是什么个情况
- 如何做出登陆时的那个滚动框,就是向登陆其他一些网站或登陆系统一样,输入用户名跟密码后出现的那个缓冲框!!!还有怎样使多行文本框(JTextArea)不能直接写入,就像QQ显示聊天内容的一样!!
- 初学java,请大家帮我看看吧!
- 这是什么错误!!
- 奇怪的问题 高分在线等待
- pdf客户端打印问题?加急!
- 送分的问题!大家积极参加
- 新闻这样的东西怎么转成中文啊??
import java.util.*;
public class Tail
{
public static void main(String args[]) throws IOException
{
if( args.length == 0 )
{
System.out.println("File not exit!") ;
}
else
{
for ( int i=0; i<args.length; i++ )
{
File f;
f=new File(args[i]);
ArrayList al=new ArrayList ();
BufferedReader in=new BufferedReader (new FileReader(f));
while (true)
{
String s = in.readLine() ;
if( s == null )
{
break ;
}
al.add( s ) ;
}
Object str1[] = al.toArray() ;
for ( int j=str1.length-10; j<str1.length; j++ )
{
System.out.println ( (String)str1[j] ) ;
}
}
}
}
}
输出文件的最后十行