创建指定路径文件|C语言 如何创建文件到指定文件夹

创建指定路径文件|C语言 如何创建文件到指定文件夹的第1张示图

Ⅰ C语言 如何创建文件到指定文件夹

C语言创建新文件可用fopen()函数的"w"(写)方式打开文件,即可。如果文件存在,将会清空现有的文件;如果不存在,则会创建该文件。

若要将文件创建到指定的文件夹下,则,在fopen()函数中的文件名,带上路径名就可以了。但,程序如果对该文件夹没有写权限,则fopen()会返回NULL。

参考代码:

#include<stdio.h>voidmain(){charfilename[100];charfilepath[100];charfile[200];FILE*fp;printf("inputfilename:");scanf("%s",filename);printf("inputfilepath:");scanf("%s",filepath);sprintf(file,"%s/%s",filepath,filename);fp=fopen(file,"w");if(fp==NULL){printf("openfile:%serror",file);return;}fputs("thisisatest!",fp);fclose(fp);}

Ⅱ 怎样用java在指定路径下创建一个文件夹

具体的创建方法参照下面的实例:public class FileTest { public static void main(String[] args) { // 根据系统的实际情况选择目录分隔符(windows下是,linux下是/) String separator = File.separator; String directory = "myDir1" + separator + "myDir2"; // 以下这句的效果等同于上面两句,windows下正斜杠/和反斜杠都是可以的// linux下只认正斜杠,为了保证跨平台性,不建议使用反斜杠(在java程序中是转义字符,用\来表示反斜杠) // String directory = "myDir1/myDir2"; String fileName = "myFile.txt"; // 在内存中创建一个文件对象,注意:此时还没有在硬盘对应目录下创建实实在在的文件 File f = new File(directory,fileName); if(f.exists()) { // 文件已经存在,输出文件的相关信息 System.out.println(f.getAbsolutePath()); System.out.println(f.getName()); System.out.println(f.length()); } else { // 先创建文件所在的目录 f.getParentFile().mkdirs(); try { // 创建新文件 f.createNewFile(); } catch (IOException e) { System.out.println("创建新文件时出现了错误。。。"); e.printStackTrace(); } } }}

Ⅲ 如何在指定的目录下创建文件夹

asp.net//文件保存的物理路径,CSTest为虚拟目录名称,F:\Inetpub\wwwroot\CSTest为物理路径[email protected]"F:\Inetpub\wwwroot\CSTest";//我们在虚拟目录的根目录下建立SchelerJob文件夹,并设置权限为匿名可修改,//SchelerJob.txt就是我们所写的文件stringFILE_NAME=p+"\\SchelerJob\\SchelerJob.txt";//取得当前服务器时间,并转换成字符串stringc=System.DateTime.Now.ToString("yyyy-mm-ddhh:MM:ss");//标记是否是新建文件的标量boolflag=false;//如果文件不存在,就新建该文件if(!File.Exists(FILE_NAME)){flag=true;StreamWritersr=File.CreateText(FILE_NAME);sr.Close();}//向文件写入内容StreamWriterx=newStreamWriter(FILE_NAME,true,System.Text.Encoding.Default);if(flag)x.Write("计划任务测试开始:");x.Write("\r\n"+c);x.Close();

Ⅳ VB创建一个文件到指定路径

源代码:Open"C:\123.txt"ForoutputAs#1’打开”C:\123.txt”如果没有则自动创建Print#1,text1.text’把文件写入文件Close#1关闭文件

Ⅳ 怎么在桌面上指定一个文件的路径

鼠标右击你要的文件,–》创建快捷方式,就可以了,然后把新建的快捷方式放到你想放的地方就行。

Ⅵ linux 中如何在指定的目录下创建文件

1、首先输入下方的代码:

#include <stdio.h>

#include <unistd.h>

#include <string.h>

#include <sys/stat.h>

int main(int argc, char *argv[])

{

FILE *file;

int opt;

char *optstring = "a:b:c:d";

char fname[50] ;

while ((opt = getopt(argc, argv, optstring)) != -1)

Ⅶ 各位大侠,c#程序中,如何根据指定路径创建文件呀谢谢了!!!!!!

首先判断你的文件夹目录是否存在若不存在则创建:if (!Directory.Exists(Server.MapPath(strPATH))){ Directory.CreateDirectory(Server.MapPath(strPATH));}接着创建文件File.Create(文件路径及名称).Close();

Ⅷ Linux上如何用终端来在指定路径下创建一个文本 另外批量创建新用户,应该如何做

1、打开LINUX系统,找到terminal。

Ⅸ WinForm程序中怎么在指定路径创建文件

1、通过Path类的Combine方法可以合并路径。 string activeDir = @"C:\myDir"; string newPath = System.IO.Path.Combine(activeDir, "mySubDirOne"); 2、目录的创建。 创建目录时如果目录已存在,则不会重新创建目录,且不会报错。创建目录时会自动创建路径中各级不存在的目录。 (1)通过Directory类的CreateDirectory方法创建。 string activeDir = @"C:\myDir"; string newPath = System.IO.Path.Combine(activeDir, "mySubDirOne"); System.IO.Directory.CreateDirectory(newPath); (1)通过DirectoryInfo的对象创建。 System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(@"C:\myDirTwo\mySubDirThree"); di.Create();

未经允许不得转载:山九号 » 创建指定路径文件|C语言 如何创建文件到指定文件夹

赞 (0)