62,625
社区成员
发帖
与我相关
我的任务
分享
public class test19 {
public static void main(String[] args) {
// TODO Auto-generated method stub
String str;
try {
FileInputStream fis=new FileInputStream("test.txt");
InputStreamReader isr=new InputStreamReader(fis);
BufferedReader bfr=new BufferedReader(isr);
while((str=bfr.readLine())!=null) {
String[] s=str.split(" ");
int[] t=new int[s.length];
for(int i=0;i<s.length;i++) {
t[i]=Integer.valueOf(s[i]);
System.out.println(t[i]);
}
}
bfr.close();
isr.close();
fis.close();
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
显示结果
11
12
133
1444
public class test18 {
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
FileOutputStream fos=new FileOutputStream("test.txt");
int[] i= {11,12,133,1444};
String[] s=new String[i.length];
for(int j=0;j<i.length;j++) {
s[j]=String.valueOf(i[j])+" ";
}
for(int j=0;j<i.length;j++) {
fos.write(s[j].getBytes());
}
fos.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}