首先我们假定www.txt中的数据读入到了一个字符串str中即
String str = "www|eee|fsd|sad|sdf";
下面这段程序可以实现你要的功能。
import java.util.*;public class FtpTest
{
public FtpTest()
{
}
public static void main(String[] args)
{
try
{
String str = "www|eee|fsd|sad|sdf";
Vector aa=new Vector ();
StringTokenizer st = new StringTokenizer(str,"|");
while (st.hasMoreTokens())
{
aa.addElement (st.nextToken());
System.out.println(aa);
}
}catch(Exception e){e.printStackTrace ();}
}
}
输出结果是:
[www]
[www, eee]
[www, eee, fsd]
[www, eee, fsd, sad]
[www, eee, fsd, sad, sdf]
String str = "www|eee|fsd|sad|sdf";
下面这段程序可以实现你要的功能。
import java.util.*;public class FtpTest
{
public FtpTest()
{
}
public static void main(String[] args)
{
try
{
String str = "www|eee|fsd|sad|sdf";
Vector aa=new Vector ();
StringTokenizer st = new StringTokenizer(str,"|");
while (st.hasMoreTokens())
{
aa.addElement (st.nextToken());
System.out.println(aa);
}
}catch(Exception e){e.printStackTrace ();}
}
}
输出结果是:
[www]
[www, eee]
[www, eee, fsd]
[www, eee, fsd, sad]
[www, eee, fsd, sad, sdf]
aa.copyInto(arr);arr就是字符串的数组啦。
aa[1]=www
aa[2]=eee
import java.io.*;
public class Test
{ public Test()
{
try{
//文件名称自己定
FileOutputStream out = new FileOutputStream("my.tmp");
ObjectOutputStream obOut = new ObjectOutputStream(out);
String[] str={"www","eee","fsd","sad","sdf"};
obOut.writeObject(str);
obOut.flush();
obOut.close();
out.close();
FileInputStream in = new FileInputStream("my.tmp");
ObjectInputStream obIn = new ObjectInputStream(in);
str=(String[])obIn.readObject();
for(int i =0 ;i < str.length;i++)
System.out.println(str[i]);
}catch(Exception e){
e.printStackTrace();
}
} public static void main(String[] args)
{
Test test = new Test(); }}
另外,可以自己写输入输出格式,根据特定的格式,获得相应信息。这样不但可以得到一维数组,就算两维,三维都可以得到