java文件应该怎么放_如何在java Eclipse中放置正确的文件路径

我想知道如何正确地放入一个文本文件,然后将其转换为一个HTML文件。

当我尝试放置一个文本文件时,我会得到错误

java.security.InvalidParameterException: Configuration file unreadable.

at com.outsideinsdk.ExportTest.parseConfig(ExportTest.java:51)

at com.outsideinsdk.ExportTest.(ExportTest.java:35)

at com.outsideinsdk.ExportTest.main(ExportTest.java:197)

下面的示例代码

package com.outsideinsdk;

import com.outsideinsdk.*;

import java.io.*;

import java.security.*;

import java.util.*;

/**

* The ExportTest class tests the {@link Export Export} technology

* according to the properties provided in a given configuration file. The

* configuration file is assumed to be correctly formatted.

*

* @author Kevin Glannon

* @version 1.00

* @see Export Export

*/

public class ExportTest

{

private static final String INPUTPATHKEY = "inputpath";

private static final String OUTPUTPATHKEY = "outputpath";

private static final String OUTPUTIDKEY = "outputid";

Properties configProps = new Properties();

/**

* Since ExportTest objects are always associated with a

* configuration file, the constructor requires a configuration file path.

*

* @param cfp The configuration file path.

*/

public ExportTest(String cfp)

throws FileNotFoundException, IOException

{

parseConfig(cfp);

}

/**

* Parse the configuration file specified by the given path.

*

* @param cfp The configuration file path.

*/

public void parseConfig(String cfp)

throws FileNotFoundException, IOException

{

// Assure the configuration file exists and is readable.

File cff = new File(cfp);

if (!cff.exists() || !cff.isFile() || !cff.canRead())

{

throw(new InvalidParameterException("Configuration file unreadable."));

}

BufferedReader cfr = new BufferedReader(new FileReader(cff));

String line;

// Loop over all lines from the file.

while ((line = cfr.readLine()) != null)

{

processLine(line);

}

}

/**

* Support the parsing of the configuration file by processing a given

* line.

*

* @param l A line from a configuration file.

*/

private void processLine(String l)

{

// Look for comments.

int indPound = l.indexOf('#');

// Remove comments and whitespace.

String line = (indPound == -1) ? l.trim() :

l.substring(0, indPound).trim();

if (line.length() != 0)

{

StringTokenizer stl = new StringTokenizer(line);

String key = stl.nextToken();

String value = stl.nextToken();

while(stl.hasMoreTokens())

{

value +=" " + stl.nextToken();

}

// Fill in the appropriate property.

configProps.setProperty(key, value);

}

}

/**

* Run the conversion using the given input path, output path.

*

* @param ifp Input path.

* @param ofp Output path.

* @param timeout Export process timeout in milliseconds.

*/

public void convert(String ifp, String ofp, long timeout)

{

String oid = configProps.getProperty(OUTPUTIDKEY);

// Display the parameters.

System.out.println("Input Path: "+ifp+" Output Path: "+ofp+

" Output ID: "+oid);

// Remove extra control properties.

configProps.remove(INPUTPATHKEY);

configProps.remove(OUTPUTPATHKEY);

// Create list of input files.

File iff = new File(ifp);

File [] iffa;

if (iff.isDirectory())

iffa = iff.listFiles();

else

{

iffa = new File[1];

iffa[0] = iff;

}

// Create output directory if needed. Assuming that if the input path

// is a directory, the output path should also be a directory.

File off = new File(ofp);

if (iff.isDirectory() && !off.exists()) off.mkdir();

// Process the conversion.

Export e = new Export(configProps);

if (off.isDirectory())

{

// The outputid is in the form fi_XXX where XXX is a reasonable

// extension so we take the extension for the oid.

// oid.substring(3) means to get the string following the fi_

String ext = "." + oid.substring(3);

for (int i=0; i

{

String ifn = iffa[i].toString();

String ofn = ofp + File.separator + iffa[i].getName() + ext;

System.out.println("Converting "+ifn+" to "+ofn);

ExportStatusCode result = e.convert(ifn, ofn, oid, timeout);

if (result.getCode() == ExportStatusCode.SCCERR_OK.getCode())

{

System.out.println("Conversion Successful!");

}

else {

System.out.println("Conversion Error: " + result);

}

}

}

else

{

for (int i=0; i

{

ExportStatusCode result = e.convert(iffa[i].toString(), ofp, oid, timeout);

if (result.getCode() == ExportStatusCode.SCCERR_OK.getCode())

{

System.out.println("Conversion Successful!");

}

else {

System.out.println("Conversion Error: " + result);

}

}

}

}

/**

* Run the test according to the given arguments. These arguments must adhere to the following usage.

* Usage:

* ExportTest InputPath OutputPath ConfigurationFile [Timeout]

*

* InputPath and OutputPath may be single files or directories. If InputPath is a directory, then all files in

* that directory will be converted, but without recursion. If OutputPath is a directory, then all converted

* files from InputPath are placed in the OutputPath directory by appending an extension which represents the

* output file type. Timeout is in milliseconds.

*

* @param args Command line arguments.

*/

public static void main(String[] args)

{

int count = args.length;

// Check for specification of configuration file.

if (count != 3 && count != 4)

{

System.out.println("Input path, output path and configuration file are required.");

System.out.println("Usage: ExportTest InputPath OutputPath "+

"ConfigurationFile [Timeout(in milliseconds)]");

System.out.println();

}

else

{

ExportTest ct = null;

try

{

ct = new ExportTest(args[2]);

}

catch (Exception ex)

{

ex.printStackTrace();

return;

}

long timeout = 0;

if( count == 4 )

{

timeout = Integer.decode( args[3] ).longValue();

}

ct.convert(args[0], args[1], timeout);

}

}

}

这是yes.txt文件在名为explorer的项目中的位置:

here

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值