1, determine whether the file exists, does not exist to create a file[Java]View Plaincopyprint?
File file=new file ("c:\\users\\qping\\desktop\\javascript\\2.htm");
if (!file.exists ())
{
try {
File.createnewfile ();
} catch
Implement code One,
#!/bin/sh # to
determine if a file exists
# link:www.jb51.net
# date:2013/2/28
mypath= '/var/log/httpd/
' myfile= ' Var/log/httpd/access.log "
# Here's the-x parameter to determine if $mypath exists and has executable
Use the Shell to judge
#!/bin/sh
mypath= "/var/log/httpd/"
myfile= "/var/log/httpd/access.log"
#-x parameter determines whether the $mypath exists and has executable permissions if [!-X "$myPath"]; Then mkdir "$myPath" FI # Here's the-D
Using a shell to determine whether a device node exists, such as inserting a 4G Modem Sierra module into a Linux system, generates a series of TTY devices, typically with a command to send and receive at. For example, a device node is a/DEV/TTYUSB2
The following is an example code that checks whether a file exists:
Copy CodeThe code is as follows:
$filename = '/path/to/foo.txt ';
if (file_exists ($filename)) {
echo "The file $filename exists";
} else {
echo "The file $filename does not exist"
Recently write code, encountered many places need to determine whether the file exists. Online methods are also strange, "the schools of contention."fopen Way open more see, there are other ways to determine whether the file exists, because other
$filename = '/path/to/foo.txt ';
if (file_exists ($filename)) {
echo "The file $filename exists";
} else {
echo "The file $filename does not exist";
}
?>
Copy CodeIf the file is present, the
1, whether the folder exists:Determine if the folder was opened successfully. DIR *dir; if((dir = opendir(path)) == NULL) { return0; } closedir(dir);2, whether the file exists: #include defining functions int Access
In most cases, you can use test commands to test the conditions. For example, you can compare strings, determine whether a file exists, and whether the file is readable. The following article describes how to use BashShell to check whether a file
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.