Java后台生成文件流
时间: 2023-05-14 15:04:28 浏览: 59
可以使用Java的FileOutputStream类来生成文件流。以下是一个简单的示例代码:
```java
import java.io.FileOutputStream;
import java.io.IOException;
public class FileGenerator {
public static void main(String[] args) {
String fileName = "example.txt";
String fileContent = "This is an example file content.";
try {
FileOutputStream outputStream = new FileOutputStream(fileName);
byte[] contentBytes = fileContent.getBytes();
outputStream.write(contentBytes);
outputStream.close();
System.out.println("File generated successfully.");
} catch (IOException e) {
System.out.println("Error generating file: " + e.getMessage());
}
}
}
```
这个程序将在当前目录下生成一个名为example.txt的文件,并将"This is an example file content."写入该文件中。