如何用JAVA新建文件
java中创建文件
import java.io.File; public class file1 {public static void main(String[] arg) throws IOException { File path=new File("F:/test"); File dir=new File(path,"hello.txt"); if(!dir.exists()) dir.createNewFile(); } } 编译时无法...展开
public void createFile(){
//path表示你所创建文件的路径
String path = "d:/tr/rt";
File f = new File(path);
if(!f.exists()){
f.mkdirs();
}
// fileName表示你创建的文件名;为txt类型;
String fileName="test.txt";
File file = new File(f,fileName);
if(!file.exists()){
try {
file.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
//现在你可以在d:/tr/rt 目录下找到test.txt文件
提示报错如下:(请大神帮忙解决) Type mismatch: cannot convert from Object to String
提示报错如下:Type mismatch: cannot convert from Object to String,是设置错误造成的,解决方法如下:1、首先打开idea软件,新建一个名为jspDemo的项目。如图是新建项目的目录结构。2、然后在web文件下的index.jsp文件中输入如下代码。3、然后在src目录下,创建一个名为indexServlet的java文件,并输入代码。4、接着,在web>WEB-INF目录下的web.xml文件中的web-app标签内,输入如下代码。5、接着,使用鼠标右键单击index.jsp文件,选择【Run 'index.jsp'】,运行程序。6、最后点击按钮后,会跳转到到servlet中,并在页面中输入填写的信息,就完成了。