成都网站建设设计

将想法与焦点和您一起共享

teajava代码 jawa代码

在Java工程下,用java代码创建文件夹

参考下面代码,说明已在代码中注释:

主要从事网页设计、PC网站建设(电脑版网站建设)、wap网站建设(手机版网站建设)、响应式网站建设、程序开发、微网站、小程序制作等,凭借多年来在互联网的打拼,我们在互联网网站建设行业积累了丰富的成都网站建设、成都网站设计、网络营销经验,集策划、开发、设计、营销、管理等多方位专业化运作于一体,具备承接不同规模与类型的建设项目的能力。

import java.io.File;

import java.io.FileOutputStream;

import java.io.IOException;

import java.text.SimpleDateFormat;

import java.util.Date;

public class WriteFile {

public static void main(String[] args) {

writeFile();

}

public static void writeFile(){

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

String content = sdf.format(new Date());

System.out.println("现在时间:" + content);

FileOutputStream out = null;

File file;

try {

String rootFile = "D:\\tests\\license";

file = new File(rootFile);

if (!file.exists()) {

/*

file.mkdirs():创建没有存在的所有文件夹

file.mkdir():创建没有存在的最后一层文件夹

例如:在硬盘上有D://test 文件夹,但是现在需要创建D://test//license//save,这个时候就需要使用file.mkdirs()而不能使用file.mkdir(),另外这两个方法都是仅仅能创建文件夹,不能创建文件,即使创建D://test//license//save//systemTime.dat如果使用该方法创建的SystemTime.dat也是一个文件夹 ,而不是文件

*/

file.mkdirs();

}

File fileDat = new File(rootFile + "\\systemFile.dat");

/*

if(!fileDat.exists()){

//创建文件 不是文件夹,在程序中这这一步没有必要,因为

new FileOutputStream(fileDat);该语句有创建文件的功能

fileDat.createNewFile();//

}

*/

out = new FileOutputStream(fileDat);

byte[] contentInBytes = content.getBytes();

out.write(contentInBytes);

out.flush();

out.close();

System.out.println("Done");

} catch (IOException e) {

e.printStackTrace();

} finally {

try {

if (out != null) {

out.close();

}

} catch (IOException e) {

e.printStackTrace();

}

}

}

}

java中的set和get只会用不知道什么意思麻烦解释下?

set/get方法是通过对数据的方法封装,实现对域的保护;怎么定义要看你具体需求;

set/get方法可以自动生成,不需要手动敲代码的。

public class Water{

private String tea;

private String milk;

public String getTea() {

return tea;

}

public void setTea(String tea) {

this.tea = tea;

}

public String getMilk() {

return milk;

}

public void setMilk(String milk) {

this.milk = milk;

}

}

java下面打*号的地方代码显示 tea cannot be resolved to a variable是什么原因

public class pro {

public static void main(String[] args) {

Teacher tea = new Teacher();

startInTeacher(tea );

System.out.println(tea.getName2()+"\n"+tea.getTeachClass()+"\n"+tea.getSex());

}

public static void startInTeacher(tea ) {

java.util.Scanner s = new java.util.Scanner(System.in);

System.out.print("please turn in:\nname:");

String name2 = s.next();

System.out.print("\nclass:");

String teachClass = s.next();

System.out.print("\nsex:");

String sex = s.next() ;

** tea.setName2 = name2;

** tea.setTeachClass = teachClass;

** tea.setSex = sex;

}

你没有定义tea,所以报错,你把它传进方法里,也行


网站名称:teajava代码 jawa代码
网站网址:http://chengdu.cdxwcx.cn/article/dddccdc.html