createfile

C++ CreateFile does not found .txt file in same folder as .exe [closed]

匿名 (未验证) 提交于 2019-12-03 08:54:24
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to use CreateFile function, but it does not go as planned. I did a simple test code : #include <Windows.h> #include <iostream> #include <tchar.h> using namespace std; int main() { HANDLE hFile; hFile = CreateFile(_T("test.txt"), GENERIC_READ, NULL, NULL, OPEN_EXISTING, NULL, NULL); if (hFile == INVALID_HANDLE_VALUE) { cout << GetLastError() << endl; Sleep(2000); return EXIT_FAILURE; } return EXIT_SUCCESS; } I generate the .exe and place a file test.txt in the same folder. When I execute the .exe I get getLastError() = 2 which

Windows下串口编程

匿名 (未验证) 提交于 2019-12-02 23:05:13
将Windows下串口编程相关信息进行下简单小结,以备后用。 1、打开串口 打开串口使用 CreateFile() 函数。以打开COM6为例: HANDLE hComm; hComm = CreateFile( TEXT("COM6"), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ); - "COM6" ,为待打开串口的串口名 。 - GENERIC_READ | GENERIC_WRITE ,为串口读写权限。 - 0,固定值。 - NULL ,指向SECURITY_ATTRIBUTES的指针。通常设置为NULL,此时CreateFile()函数返回的句柄不能被子进程继承。 - OPEN_EXISTING,固定值。 - FILE_ATTRIBUTE_NORMAL ,文件属性。 - NULL,固定值。 - hComm ,函数返回的句柄。如果打开串口成功,则在后续操作中使用该句柄访问串口。如果打开串口失败,函数返回句柄为 INVALID_HANDLE_VALUE 。 这里需要额外说明两点 一是 CreateFile()、CreateFileA() 1 和CreateFileW() 2 的区别 。在大部分说明如何使用Win32

How to create file directories and folders in Android data/data/project filesystem

瘦欲@ 提交于 2019-12-02 20:53:27
I am working on a video editor program and am fairly new to android and java. What I would like to happen is when the user presses "create new project" button, a dialog pops up asking the user for the name of the project. I have that part down, but what I then want, is when the user presses "ok" on that dialog, my code will take the name and create a directory inside of my data/data file for my project and inside of that directory create folders titled 1 to 5 or more. I really don't know how to go about this, so any input would be truly appreciated. As sgarman proposed you can use the SD card

Novice Batch Issue- Creating Files

南楼画角 提交于 2019-12-02 08:40:07
I was working on developing a batch program that would scan various sections of a PC, and log them to a file. Surprisingly, I was unable to have the program create the file to write to. I then tried to create a file, that I was fairly certain would work; it is as followed: @echo off ipconfig > ip.txt timeout 5 However, this was also unable to write to the file ip.txt . I also attempted the following program, with no success. @echo off echo Test > test.txt timeout 3 If anyone would be able to give advice, I would much appreciate it. No error messages are present, and clicking the link batch

html or java script code to create a text file in hard disk

試著忘記壹切 提交于 2019-12-02 08:36:06
Please someone give me a code to create a text file in hard drive Result should be a html file, when double click html file it need to create a text file in a given path in hard drive(local). Thank you. Javascript in a regular HTML page in a browser is not allowed direct access to a path of your choice on the hard disk for security reasons. The, somewhat experimental, FileSystem APIs in newer browsers offering some capabilities to a sandboxed file system, but you will have to see if your need can be satisfied with those APIs. Other than that, you would need some way around the security

File.createNewFile() randomly fails

老子叫甜甜 提交于 2019-12-02 06:32:05
I've build a simple test which creates and deletes a file (name does not change) in an infinite loop. The test does run for a couple of seconds (sometimes over 77,000 iterations!) and then fails with this exception: Exception in thread "main" java.io.IOException: Access is denied at java.io.WinNTFileSystem.createFileExclusively(Native Method) at java.io.File.createNewFile(Unknown Source) at DeleteTest.main(DeleteTest.java:11) Here's the test logic: final File f = new File(pathname); while (true) { final boolean create = f.createNewFile(); if (!create) { System.out.println("crate failed"); }

第三十二篇 -- CreateFile、ReadFile、WriteFile

空扰寡人 提交于 2019-12-01 15:11:27
一、 CreateFile 这是一个多功能的函数,可打开或创建文件或者I/O设备,并返回可访问的句柄:控制台,通信资源,目录(只读打开),磁盘驱动器,文件,邮槽,管道。 函数原型: HANDLE WINAPI CreateFile( _In_ LPCTSTR lpFileName, _In_ DWORD dwDesiredAccess, _In_ DWORD dwShareMode, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _In_ DWORD dwCreationDisposition, _In_ DWORD dwFlagsAndAttributes, _In_opt_ HANDLE hTemplateFile ); View Code 返回值: Long,如执行成功,则返回文件句柄。INVALID_HANDLE_VALUE表示出错,会设置GetLastError。即使函数成功,但若文件存在,且指定了CREATE_ALWAYS 或 OPEN_ALWAYS,GetLastError也会设为ERROR_ALREADY_EXISTS 函数声明: HANDLE CreateFile(LPCTSTR lpFileName, //普通文件名或者设备文件名 DWORD dwDesiredAccess, //访问模式(写/读)

Create and download a text file using php

我的未来我决定 提交于 2019-12-01 09:26:11
Here's what I'm trying to do. I have a series of reports that they also want to be able to download as comma delimited text files. I've read over a bunch of pages where people say simply echo out the results rather than creating a file, but when I try that it just outputs to the page they are on. I have this in the form of each report Export File<input type="checkbox" name="export" value="1" /> So on the post I can check if they are trying to export the file. If they are I was trying to do this: if($_POST['export'] == '1') { $filename = date("Instructors by DOB - ".$month) . '.txt'; $content =

CreateTextFile not working when hta is set to open as notepad by default (javascripting)

孤人 提交于 2019-12-01 09:22:28
问题 I'm getting this really weird problem when I try to create a text file using javascripting and a hta file. This is the code broken down to its basics: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script> alert("creating file"); var fso = new ActiveXObject("Scripting

CreateFile CREATE_NEW equivalent on linux

主宰稳场 提交于 2019-12-01 08:23:57
I wrote a method which tries to create a file. However I set the flag CREATE_NEW so it can only create it when it doesnt exist. It looks like this: for (;;) { handle_ = CreateFileA(filePath.c_str(), 0, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_HIDDEN | FILE_FLAG_DELETE_ON_CLOSE, NULL); if (handle_ != INVALID_HANDLE_VALUE) break; boost::this_thread::sleep(boost::posix_time::millisec(10)); } This works as it should. Now I want to port it to linux and and of course the CreateFile function are only for windows. So I am looking for something equivalent to this but on linux. I already looked at open() but