📄 writefile.java
字号:
package com.chapter4;
import java.io.*;
public class WriteFile
{
//类成员变量
private String path;
private String content;
//初始化
public WriteFile()
{
this.path = "";
this.content = "default content";
}
//设置文件路径
public void setPath(String path)
{
this.path = path;
}
//得到文件路径
public String getPath()
{
return this.path;
}
//获取所要写入的内容
public void setContent(String content)
{
this.content = content;
}
//设置所要写入的内容
public String getContent()
{
return this.content;
}
//写入字符串到文件中
public int writeContent()
{
int r = 0;
try
{
File fObj = new File(this.path);
PrintWriter out = new PrintWriter(new FileWriter(fObj));
out.print(this.getContent());
out.close();
}
catch (IOException e)
{
r = -1;
}
return r;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -