怎么读到数组? 是不是可以先放到HashMap中,然后再存到数组中?楼主自己试试吧:) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我自己编写了一个类可有报错~~大家帮我看看是什么原因~import java.io.*;import java.lang.*;class zcy{ String s[]; int i; public static void main(String args[]) throws Exception { System.out.println("dd"); char c; StringBuffer buf = new StringBuffer(); while((c=(char)System.in.read())!='\n') ; buf.append(c); byte b[]=buf.toString().trim().getBytes(); RandomAccessFile f1 = new RandomAccessFile("zz.txt","rw"); f1.seek(f1.length()); f1.write(b); f1.writeBytes( System.getProperty( "line.separator" ) ); f1.close(); } public static void shuzu() //这个方法就是想把文本文件的的内容存放到数组里 { RandomAccessFile f2 = new RandomAccessFile("zz.txt","r"); f2.seek(0); for(i=0;i<10;i++) { s[i]=f2.readLine(); f2.seek(f2.getFilePointer()); } } }但是有很多错误~ 大家看看那里的问题~ 我是初学 刚接触JAVA一个月~ 真心感谢 写了一个class,楼主你自己研究下吧package main;import java.util.Vector;import java.io.File;import java.io.FileReader;import java.io.BufferedReader;import java.io.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2002</p> * <p>Company: </p> * @author not attributable * @version 1.0 */public class ReadTxt { public static void main (String[] arg) { Vector fileContent = new Vector(); try { FileReader fileReader = new FileReader(new File( "C:\\Documents and Settings\\Owner\\桌面\\read.txt")); BufferedReader br = new BufferedReader(fileReader); while (br.ready()) { fileContent.add(br.readLine()); } br.close(); fileReader.close(); } catch (IOException ex) { System.out.println("Got IOException : " +ex.toString()); } String[] content = new String[fileContent.size()]; System.arraycopy(fileContent.toArray(),0,content,0,fileContent.size()); for (int i =0;i < content.length;i++) { System.out.println(content[i]); } }} FileReader fileReader = new FileReader(new File( "C:\\Documents and Settings\\Owner\\桌面\\read.txt"));换成你要读的文件路径 非常感谢~~(只睡六小时)的解答 ~~有个问题不太懂能否解释一下~~你所用的~~Vector的类 主要功能是什么~ 能详细说一下吗~~还有就是如果数组里有个元素是“99”那么用什么方法可以知道它是数组的第几个元素??就是Array[i]=99哪个i的数字?? 真心谢谢你:) Vector是个动态数组初始化时,会分配一定量的数组空间如果溢出,会重新定义大小不能,因为加进去的对象可能是重复的 java 环境变量中的classpath ,class_home 怎么配置 这个程序怎么改 java的一点小问题 JAVA新手-怎么获得键盘输入??? 求Thinking in java 大虾们,怎么读取一个word文件,帮帮忙 有关捕捉异常的问题,急!!! 可执行jar的支持包问题 急!!!!!日期检验的问题 请问如何做文件上传?急呀!来就有分! 请问谁有jcreator3.0的注册码呀? 关于方法的烦恼
import java.io.*;
import java.lang.*;
class zcy
{
String s[];
int i;
public static void main(String args[]) throws Exception
{
System.out.println("dd");
char c;
StringBuffer buf = new StringBuffer();
while((c=(char)System.in.read())!='\n')
;
buf.append(c);
byte b[]=buf.toString().trim().getBytes();
RandomAccessFile f1 = new RandomAccessFile("zz.txt","rw");
f1.seek(f1.length());
f1.write(b);
f1.writeBytes( System.getProperty( "line.separator" ) );
f1.close();
}
public static void shuzu() //这个方法就是想把文本文件的的内容存放到数组里
{
RandomAccessFile f2 = new RandomAccessFile("zz.txt","r");
f2.seek(0);
for(i=0;i<10;i++)
{
s[i]=f2.readLine();
f2.seek(f2.getFilePointer());
}
}
}
但是有很多错误~ 大家看看那里的问题~ 我是初学 刚接触JAVA一个月~ 真心感谢
package main;import java.util.Vector;
import java.io.File;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.*;/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/public class ReadTxt {
public static void main (String[] arg) {
Vector fileContent = new Vector();
try {
FileReader fileReader = new FileReader(new File(
"C:\\Documents and Settings\\Owner\\桌面\\read.txt"));
BufferedReader br = new BufferedReader(fileReader);
while (br.ready()) {
fileContent.add(br.readLine());
}
br.close();
fileReader.close();
}
catch (IOException ex) {
System.out.println("Got IOException : " +ex.toString());
}
String[] content = new String[fileContent.size()];
System.arraycopy(fileContent.toArray(),0,content,0,fileContent.size());
for (int i =0;i < content.length;i++) {
System.out.println(content[i]);
}
}
}
"C:\\Documents and Settings\\Owner\\桌面\\read.txt"));
换成你要读的文件路径
你所用的~~Vector的类 主要功能是什么~ 能详细说一下吗~~
还有就是如果数组里有个元素是“99”那么用什么方法可以知道它是数组的第几个元素??
就是Array[i]=99
哪个i的数字?? 真心谢谢你:)
初始化时,会分配一定量的数组空间
如果溢出,会重新定义大小不能,因为加进去的对象可能是重复的