日期:2014-05-20 浏览次数:20694 次
import java.io.FileWriter; import java.io.File; public class FileWriterDemo { public static void main(String[] args)throws Exception { File f=new File("number.txt"); if(!f.exists()) f.createNewFile(); FileWriter fw=new FileWriter(f); int[] randomAry=new int[10];//假设10个随机数 for(int i=0;i<randomAry.length;i++){ randomAry[i]=(int)(Math.random()*100); fw.write(new Integer(randomAry[i]).toString()+" "); } fw.close(); } }
------解决方案--------------------
其实对asc ii码来说,想怎么写就怎么写.
static void t5(){ OutputStream out = null; String str = null; try{ out = new FileOutputStream("d:\\test\\1\\11.txt"); str = 123+""; out.write(str.getBytes()); out.close(); }catch(Exception ex){ ex.printStackTrace(); } }