java怎样创建TXT文件 越简单越好,最好能运行。请教高手。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 import java.io.File;import java.io.IOException;public class Test { public static void main(String[] args) throws IOException { File file = new File("a.txt"); if (!file.exists()) { boolean b = file.createNewFile(); System.out.println(b ? "文件创建成功" : "文件创建失败"); } }} 自己看看http://topic.csdn.net/u/20110108/09/4f9315a2-84cd-4f40-9a5e-645d9bb251d6.htmlimport java.io.*;import java.util.ArrayList;import java.util.List;public class TXT { public static void main(String[] args){ List names=new ArrayList(); names.add("name1"); names.add("name2"); names.add("name3"); names.add("name4"); names.add("name5"); File f = new File("E:\\123.txt"); if(f.exists()){ System.out.print("文件存在"); }else{ System.out.print("文件不存在"); try { f.createNewFile(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }//不存在则创建 } try { BufferedReader input = new BufferedReader(new FileReader(f)); BufferedWriter output = new BufferedWriter(new FileWriter(f)); for(int i=0;i<names.size();i++) output.write((String)names.get(i)+"\r\n"); output.close(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }} import java.io.File;import java.io.IOException;/** * 新建文件实例代码 */public class CreateTxtFile { public static void main(String[] args) throws IOException { File file = new File("c:/newTxtFile.txt"); //父目录如果不存在,那么先新建父目录 if(!file.getParentFile().exists()){ file.getParentFile().mkdirs(); } //判断文件是否存在,不存在新建 if(!file.exists()){ file.createNewFile(); } }} import java.io.File;public class Test{ public static void main(String[] args) { try{ File file = new File("a.txt"); file.createNewFile(); }catch(Exception e) { e.printStackTrace(); } }} //创建一个文件对象 File file=new File("d:\\output.text"); new 完 File 还要create一下。 import java.io.File; import java.io.IOException; public class Test { public static void main(String[] args) throws IOException { File file = new File("a.txt"); if (!file.exists()) { boolean b = file.createNewFile(); System.out.println(b ? "文件创建成功" : "文件创建失败"); } } } #include <stdio.h>#include <string.h>int main(){ FILE txt = open("c:/1.txt","rb+"); if(txt == NULL) { printf("Create 1.txt fail"); return -1; } } 怎么样区分数组和对象 给位高手帮帮忙啊。。。。关于内部类的问题 哪个JDK版本支持sun solaris 64位编译C++程序? new到底怎样解 我不理解的是为什么最后一句还要加getFirstChild() Java中,如何保留两位小数点?? 哪位有java的类的结构继承图一类的东东,谢谢!! 目前比较流行的GUi框架有没有人推荐啊 请教各位老大,怎么把数据库中的记录按行输入到文本文件中? 急!!!如何使用Broland Enterprise Server开发分布式应用程序 Java中窗体关闭问题 为什么这个数组没法调用
import java.io.IOException;public class Test {
public static void main(String[] args) throws IOException {
File file = new File("a.txt");
if (!file.exists()) {
boolean b = file.createNewFile();
System.out.println(b ? "文件创建成功" : "文件创建失败");
}
}
}
http://topic.csdn.net/u/20110108/09/4f9315a2-84cd-4f40-9a5e-645d9bb251d6.htmlimport java.io.*;
import java.util.ArrayList;
import java.util.List;
public class TXT {
public static void main(String[] args){
List names=new ArrayList();
names.add("name1");
names.add("name2");
names.add("name3");
names.add("name4");
names.add("name5");
File f = new File("E:\\123.txt");
if(f.exists()){
System.out.print("文件存在");
}else{
System.out.print("文件不存在");
try {
f.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}//不存在则创建
} try {
BufferedReader input = new BufferedReader(new FileReader(f));
BufferedWriter output = new BufferedWriter(new FileWriter(f));
for(int i=0;i<names.size();i++)
output.write((String)names.get(i)+"\r\n");
output.close(); } catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}}
import java.io.File;
import java.io.IOException;/**
* 新建文件实例代码
*/
public class CreateTxtFile {
public static void main(String[] args) throws IOException {
File file = new File("c:/newTxtFile.txt");
//父目录如果不存在,那么先新建父目录
if(!file.getParentFile().exists()){
file.getParentFile().mkdirs();
}
//判断文件是否存在,不存在新建
if(!file.exists()){
file.createNewFile();
}
}
}
public class Test
{
public static void main(String[] args)
{
try{
File file = new File("a.txt");
file.createNewFile();
}catch(Exception e)
{
e.printStackTrace();
} }
}
//创建一个文件对象
File file=new File("d:\\output.text");
import java.io.IOException; public class Test {
public static void main(String[] args) throws IOException {
File file = new File("a.txt");
if (!file.exists()) {
boolean b = file.createNewFile();
System.out.println(b ? "文件创建成功" : "文件创建失败");
}
}
}
#include <stdio.h>
#include <string.h>int main()
{
FILE txt = open("c:/1.txt","rb+");
if(txt == NULL)
{
printf("Create 1.txt fail");
return -1;
}
}