java 简单小程序

来源:百度知道 编辑:UC知道 时间:2024/07/16 03:56:27
package user.file;
import java.io.*;
public class WriterFile
{
String filePath=null,
fileName=null,
fileContent=null;
boolean success;
public void setFilePath(String s)
{
filePath=s;
try
{
File Path=new File(filePath);
path.mkdir();
}
catch(Exception e){ }
}
public String getFilePath()
{
return filePath;
}
public void setFileName(String s)
{
fileName=s;
}
public string getFileName()
{
return fileName;
}
public void setFileContent(String s)
{
fileContent=s;
byte content[]=fileContent.get.getBytes();
try
{
File file=new File(filePath,fileName);
FileOutputStream in=new FileOutputStream(file);
in.write(content,0,content.length);
in.close();
success=true;
}
catch(Exception e)
{
success=false;
}

//程序改成如下就没有错误了//

package com.zte;

import java.io.*;

class WriterFile {
String filePath = null, fileName = null, fileContent = null;

boolean success;

public void setFilePath(String s) {
filePath = s;
try {
File path = new File(filePath); // 2
path.mkdir();
} catch (Exception e) {
}
}

public String getFilePath() {
return filePath;
}

public void setFileName(String s) {
fileName = s;
}

// 1
public String getFileName() {
return fileName;
}

public void setFileContent(String s) {
fileContent = s;
byte content[] = fileContent.getBytes(); // 3
try {
File file = new File(filePath, fileName);
FileOutputStream in = new FileOutputStream(file);
in.write(content, 0, content.length);
in.close();
success = true;
} catch (Exception