将字符串写入文件
Posted yesiming
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了将字符串写入文件相关的知识,希望对你有一定的参考价值。
将字符串写入文件
#include <stdio.h>
#include <stdlib.h>
int main()
char sentence[1000];
FILE *fptr;
fptr=fopen("runoob.txt","w");
if(fptr==NULL)
printf("error");
exit(1);
printf("输入字符串:\\n");
fgets(sentence, (sizeof sentence / sizeof sentence[0]), stdin);
fprintf(fptr,"%s", sentence);
fclose(fptr);
return 0;
java如何将一个InputStream写入文件?
参考技术Ajava通过InputStream读取和写入文件操作实例代码
1. File to InputStream
File file = new File("file.xml");
InputStream inputStream = new FileInputStream(file);
2.InputStream to File
InputStream inputStream = new FileInputStream("file.xml");
OutputStream outputStream = new FileOutputStream("file-new.xml");
int bytesWritten = 0;
int byteCount = 0;
byte[] bytes = new byte[1024];
while ((byteCount = inputStream.read(bytes)) != -1)
outputStream.write(bytes, bytesWritten, byteCount);
bytesWritten += byteCount;
inputStream.close();
outputStream.close();
以上是关于将字符串写入文件的主要内容,如果未能解决你的问题,请参考以下文章