⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exist.java

📁 JAVA 数学程序库 提供常规的数值计算程序包
💻 JAVA
字号:
package jmathlib.toolbox.io;

import jmathlib.core.tokens.Token;
import jmathlib.core.tokens.OperandToken;
import jmathlib.core.tokens.numbertokens.DoubleNumberToken;
import jmathlib.core.functions.ExternalFunction;
import java.io.*;

/**An external function used to check if a file exists*/
public class exist extends ExternalFunction
{
	/**Check if file exists
	@param 0 = filename
	@return 1 if the file exists*/
	public OperandToken evaluate(Token[] operands)
	{
    
    	// at least one operand
        if (getNArgIn(operands) != 1)
			throwMathLibException("exist: number of arguments != 1");

    
		String fileName = operands[0].toString();
		File testFile = null;
		if((fileName.indexOf(":") > -1))
			testFile = new File(fileName);
		else
		{
			File path = getWorkingDirectory();
			testFile = new File(path, fileName);
		}
		
		OperandToken result = null;
		
		if(testFile.exists())
			result = new DoubleNumberToken(1);
		else
			result = new DoubleNumberToken(0);
			
		return result;
	}
}

/*
@GROUP
IO
@SYNTAX
exist(filename)
@DOC
Checks if a file exists
@EXAMPLES
<programlisting>
exist("bar.txt")
</programlisting>
@SEE
cd, createnewfile, dir, mkdir, rmdir, delete, isfile, isdirectory, ishidden, lastmodified
*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -