import java.io.*;
public class test
{
public static void main(String []args)
{
String s = new String("hello every\n");//这里的字符串可以换
int bytes;
try
{ ByteArrayInputStream bis = new ByteArrayInputStream (s.getBytes());
FileOutputStream fos=new FileOutputStream("Target.txt",true);
while((bytes=bis.read())!=-1)
{ fos.write(bytes); }
bis.close();
fos.close();
}catch(IOException e){}
}
}
public class ReadFileTest
{
public static void main(String[] args)
{
//读入
try{
BufferedReader br = new BufferedReader(new FileReader("t.txt"));
String line;
StringBuffer buffer=new StringBuffer();
line=br.readLine();
StringTokenizer st = new StringTokenizer(line);
String[] t = new String[]{"first_",",second_",",third_"};
int i=0;
String result = "";
while(st.hasMoreTokens())
{
result=result + t[i] + st.nextToken();
i++;
}
result = result + ",end.";
用StringTokenizer的方法
String s = "abc ef ghijk";
StringTokenizer st = new StringTokenizer(s);
String[] t = new String[]{"first","second","third"};
int i=0;
String result = "";
while(st.hasMoreTokens())
{
result=result + t[i] + st.nextToken();
i++;
}
result = result + "end.";