当前位置: 首页 > 工具软件 > Touch4j > 使用案例 >

java touch创建文件_Java FileUtils.touch方法代碼示例

壤驷高旻
2023-12-01

本文整理匯總了Java中org.apache.commons.io.FileUtils.touch方法的典型用法代碼示例。如果您正苦於以下問題:Java FileUtils.touch方法的具體用法?Java FileUtils.touch怎麽用?Java FileUtils.touch使用的例子?那麽恭喜您, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.io.FileUtils的用法示例。

在下文中一共展示了FileUtils.touch方法的18個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Java代碼示例。

示例1: touch

​點讚 3

import org.apache.commons.io.FileUtils; //導入方法依賴的package包/類

public TestFile touch() {

try {

FileUtils.touch(this);

} catch (IOException e) {

throw new RuntimeException(e);

}

assertIsFile();

return this;

}

開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:10,

示例2: touch

​點讚 3

import org.apache.commons.io.FileUtils; //導入方法依賴的package包/類

public static void touch(File file) {

try {

FileUtils.touch(file);

} catch (IOException e) {

throw new UncheckedIOException(e);

}

}

開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:8,

示例3: batch_should_skip_on_second_scan

​點讚 3

import org.apache.commons.io.FileUtils; //導入方法依賴的package包/類

@Test

public void batch_should_skip_on_second_scan() throws IOException {

long fileSize = ((Contants.REGION_SIZE * SlowFileProcessor.BATCH_SIZE) * 2) + 1;

String workingDirectory = "/home/gaganis/IdeaProjects/DirectorySynchronizer/testdata/source";

String fileName = "ubuntu-16.04.1-desktop-amd64.iso";

File file = new File(fileName);

updateAbsolutePath(file, workingDirectory, fileName);

FileProcessor fileProcessor = getFileProcessor(fileSize, workingDirectory, file);

BatchArea batchArea = fileProcessor.nextBatchArea();

assertThat(batchArea.isSkip).isFalse();

fileProcessor.doBeforeBatchByteRead();

fileProcessor.process(

new byte[(int) (Contants.REGION_SIZE * SlowFileProcessor.BATCH_SIZE)],

batchArea);

fileProcessor = getFileProcessor(fileSize, workingDirectory, file);

batchArea = fileProcessor.nextBatchArea();

assertThat(batchArea.isSkip).isTrue();

FileUtils.touch(file.getAbsolutePath().toFile());

}

開發者ID:gaganis,項目名稱:odoxSync,代碼行數:23,

示例4: testUploadFileStraightForward

​點讚 3

import org.apache.commons.io.FileUtils; //導入方法依賴的package包/類

@Test

public void testUploadFileStraightForward() throws Exception {

setMock(setupMock());

String fileName = UUID.randomUUID().toString() + ".txt";

File upload = tmp.newFile(fileName);

FileUtils.touch(upload);

UploadFileToTransport.main(new String[] {

"-u", SERVICE_USER,

"-p", SERVICE_PASSWORD,

"-e", SERVICE_ENDPOINT,

"dummy-cmd",

"8000042445", "L21K90002J", "HCP", upload.getAbsolutePath()

});

assertThat(changeId.getValue(), is(equalTo("8000042445")));

assertThat(transportId.getValue(), is(equalTo("L21K90002J")));

assertThat(filePath.getValue(), endsWith(fileName));

assertThat(applicationId.getValue(), is(equalTo("HCP")));

}

開發者ID:SAP,項目名稱:devops-cm-client,代碼行數:23,

示例5: train

​點讚 3

import org.apache.commons.io.FileUtils; //導入方法依賴的package包/類

public void train() {

try {

InputStreamFactory modelStream = new MarkableFileInputStreamFactory(

new File(getClass().getClassLoader().getResource(TRAIN_INPUT).getFile())

);

final ObjectStream lineStream = new PlainTextByLineStream(modelStream, "UTF-8");

final ObjectStream sampleStream = new DocumentSampleStream(lineStream);

final TrainingParameters mlParams = new TrainingParameters();

mlParams.put(TrainingParameters.ITERATIONS_PARAM, 5000);

mlParams.put(TrainingParameters.CUTOFF_PARAM, 5);

final DoccatModel model = DocumentCategorizerME.train("en", sampleStream, mlParams, new DoccatFactory());

final Path path = Paths.get(MODEL_OUTPUT);

FileUtils.touch(path.toFile());

try (OutputStream modelOut = new BufferedOutputStream(new FileOutputStream(path.toString()))) {

model.serialize(modelOut);

}

} catch (Exception e) {

LOGGER.error("an error occurred while training the sentiment analysis model", e);

throw new IllegalStateException(e);

}

}

開發者ID:kalnee,項目名稱:trivor-nlp,代碼行數:24,

示例6: createTempFile

​點讚 2

import org.apache.commons.io.FileUtils; //導入方法依賴的package包/類

@Override

public File createTempFile(final String prefix, final String suffix) throws IOException {

final File file = new File(folder, fileUniqueNameGenerator.get(prefix) + suffix);

FileUtils.touch(file);

tempFiles.add(file);

return file;

}

開發者ID:subes,項目名稱:invesdwin-context-r,代碼行數:8,

示例7: testTouchSkip

​點讚 2

import org.apache.commons.io.FileUtils; //導入方法依賴的package包/類

public static void testTouchSkip(File file, Supplier fileProcessorSupplier, long byteArraySize) throws IOException, InterruptedException {

FileProcessor fileProcessor = fileProcessorSupplier.get();

fileProcessor.doBeforeFileRead(null);

BatchArea batchArea = fileProcessor.nextBatchArea();

assertThat(batchArea.isSkip).isFalse();

fileProcessor.doBeforeBatchByteRead();

fileProcessor.process(

new byte[(int) byteArraySize],

batchArea);

//2nd pass

fileProcessor = fileProcessorSupplier.get();

fileProcessor.doBeforeFileRead(null);

batchArea = fileProcessor.nextBatchArea();

assertThat(batchArea.isSkip).isTrue();

Thread.sleep(1000);//The 1 second precision of touch makes the test flaky, hence the sleep to make the touch roll to the next second

FileUtils.touch(file.getAbsolutePath().toFile());

//3rd pass

fileProcessor = fileProcessorSupplier.get();

fileProcessor.doBeforeFileRead(null);

batchArea = fileProcessor.nextBatchArea();

assertThat(batchArea.isSkip).isFalse();

}

開發者ID:gaganis,項目名稱:odoxSync,代碼行數:28,

示例8: testImportFromM3U

​點讚 2

import org.apache.commons.io.FileUtils; //導入方法依賴的package包/類

@Test

public void testImportFromM3U() throws Exception {

String username = "testUser";

String playlistName = "test-playlist";

StringBuilder builder = new StringBuilder();

builder.append("#EXTM3U\n");

File mf1 = folder.newFile();

FileUtils.touch(mf1);

File mf2 = folder.newFile();

FileUtils.touch(mf2);

File mf3 = folder.newFile();

FileUtils.touch(mf3);

builder.append(mf1.getAbsolutePath() + "\n");

builder.append(mf2.getAbsolutePath() + "\n");

builder.append(mf3.getAbsolutePath() + "\n");

doAnswer(new PersistPlayList(23)).when(playlistDao).createPlaylist(any());

doAnswer(new MediaFileHasEverything()).when(mediaFileService).getMediaFile(any(File.class));

InputStream inputStream = new ByteArrayInputStream(builder.toString().getBytes("UTF-8"));

String path = "/path/to/"+playlistName+".m3u";

playlistService.importPlaylist(username, playlistName, path, inputStream, null);

verify(playlistDao).createPlaylist(actual.capture());

verify(playlistDao).setFilesInPlaylist(eq(23), medias.capture());

Playlist expected = new Playlist();

expected.setUsername(username);

expected.setName(playlistName);

expected.setComment("Auto-imported from " + path);

expected.setImportedFrom(path);

expected.setShared(true);

expected.setId(23);

assertTrue("\n" + ToStringBuilder.reflectionToString(actual.getValue()) + "\n\n did not equal \n\n" + ToStringBuilder.reflectionToString(expected), EqualsBuilder.reflectionEquals(actual.getValue(), expected, "created", "changed"));

List mediaFiles = medias.getValue();

assertEquals(3, mediaFiles.size());

}

開發者ID:airsonic,項目名稱:airsonic,代碼行數:34,

示例9: testImportFromPLS

​點讚 2

import org.apache.commons.io.FileUtils; //導入方法依賴的package包/類

@Test

public void testImportFromPLS() throws Exception {

String username = "testUser";

String playlistName = "test-playlist";

StringBuilder builder = new StringBuilder();

builder.append("[playlist]\n");

File mf1 = folder.newFile();

FileUtils.touch(mf1);

File mf2 = folder.newFile();

FileUtils.touch(mf2);

File mf3 = folder.newFile();

FileUtils.touch(mf3);

builder.append("File1=" + mf1.getAbsolutePath() + "\n");

builder.append("File2=" + mf2.getAbsolutePath() + "\n");

builder.append("File3=" + mf3.getAbsolutePath() + "\n");

doAnswer(new PersistPlayList(23)).when(playlistDao).createPlaylist(any());

doAnswer(new MediaFileHasEverything()).when(mediaFileService).getMediaFile(any(File.class));

InputStream inputStream = new ByteArrayInputStream(builder.toString().getBytes("UTF-8"));

String path = "/path/to/"+playlistName+".pls";

playlistService.importPlaylist(username, playlistName, path, inputStream, null);

verify(playlistDao).createPlaylist(actual.capture());

verify(playlistDao).setFilesInPlaylist(eq(23), medias.capture());

Playlist expected = new Playlist();

expected.setUsername(username);

expected.setName(playlistName);

expected.setComment("Auto-imported from " + path);

expected.setImportedFrom(path);

expected.setShared(true);

expected.setId(23);

assertTrue("\n" + ToStringBuilder.reflectionToString(actual.getValue()) + "\n\n did not equal \n\n" + ToStringBuilder.reflectionToString(expected), EqualsBuilder.reflectionEquals(actual.getValue(), expected, "created", "changed"));

List mediaFiles = medias.getValue();

assertEquals(3, mediaFiles.size());

}

開發者ID:airsonic,項目名稱:airsonic,代碼行數:34,

示例10: testImportFromXSPF

​點讚 2

import org.apache.commons.io.FileUtils; //導入方法依賴的package包/類

@Test

public void testImportFromXSPF() throws Exception {

String username = "testUser";

String playlistName = "test-playlist";

StringBuilder builder = new StringBuilder();

builder.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"

+ "\n"

+ " \n");

File mf1 = folder.newFile();

FileUtils.touch(mf1);

File mf2 = folder.newFile();

FileUtils.touch(mf2);

File mf3 = folder.newFile();

FileUtils.touch(mf3);

builder.append("file://" + mf1.getAbsolutePath() + "\n");

builder.append("file://" + mf2.getAbsolutePath() + "\n");

builder.append("file://" + mf3.getAbsolutePath() + "\n");

builder.append(" \n" + "\n");

doAnswer(new PersistPlayList(23)).when(playlistDao).createPlaylist(any());

doAnswer(new MediaFileHasEverything()).when(mediaFileService).getMediaFile(any(File.class));

InputStream inputStream = new ByteArrayInputStream(builder.toString().getBytes("UTF-8"));

String path = "/path/to/"+playlistName+".xspf";

playlistService.importPlaylist(username, playlistName, path, inputStream, null);

verify(playlistDao).createPlaylist(actual.capture());

verify(playlistDao).setFilesInPlaylist(eq(23), medias.capture());

Playlist expected = new Playlist();

expected.setUsername(username);

expected.setName(playlistName);

expected.setComment("Auto-imported from " + path);

expected.setImportedFrom(path);

expected.setShared(true);

expected.setId(23);

assertTrue("\n" + ToStringBuilder.reflectionToString(actual.getValue()) + "\n\n did not equal \n\n" + ToStringBuilder.reflectionToString(expected), EqualsBuilder.reflectionEquals(actual.getValue(), expected, "created", "changed"));

List mediaFiles = medias.getValue();

assertEquals(3, mediaFiles.size());

}

開發者ID:airsonic,項目名稱:airsonic,代碼行數:37,

示例11: writeObject

​點讚 2

import org.apache.commons.io.FileUtils; //導入方法依賴的package包/類

static void writeObject(Attributes obj, String txUid, String classUid)

throws IOException

{

String studyUid = obj.getString(Tag.StudyInstanceUID);

String seriesUid = obj.getString(Tag.SeriesInstanceUID);

String instanceUid = obj.getString(Tag.SOPInstanceUID);

File dcmFile = buildFile(studyUid, seriesUid, instanceUid, "dcm");

File tmpFile = buildFile(studyUid, seriesUid, instanceUid, "tmp");

File errFile = buildFile(studyUid, seriesUid, instanceUid, "err");

try {

if (errFile.isFile()) {

logger.info("Overwriting error file: {}", errFile);

FileUtils.deleteQuietly(errFile);

}

FileUtils.touch(tmpFile); // Create parent directories if needed

try (FileOutputStream fos = new FileOutputStream(tmpFile)) {

if (UID.ImplicitVRLittleEndian.equals(txUid)) {

// DicomOutputStream throws exception when writing dataset with LEI

txUid = UID.ExplicitVRLittleEndian;

}

else if (UID.ExplicitVRBigEndianRetired.equals(txUid)) {

// Should never happen, but just in case

txUid = UID.ExplicitVRLittleEndian;

logger.info("Trancoding dataset from big to "

+ "little endian for: {}", dcmFile);

}

Attributes fmi = Attributes.createFileMetaInformation(instanceUid,

classUid,

txUid);

DicomOutputStream dos = new DicomOutputStream(fos, txUid);

dos.writeDataset(fmi, obj);

dos.close();

}

Files.move(tmpFile.toPath(),

dcmFile.toPath(),

StandardCopyOption.ATOMIC_MOVE,

StandardCopyOption.REPLACE_EXISTING);

}

catch (Exception ex) {

logger.warn("Unable save DICOM object to: " + dcmFile, ex);

FileUtils.touch(errFile);

FileUtils.deleteQuietly(tmpFile);

FileUtils.deleteQuietly(dcmFile);

if (ex instanceof IOException) {

throw (IOException) ex;

}

else {

throw new IOException(ex);

}

}

}

開發者ID:RSNA,項目名稱:dcmrs-broker,代碼行數:63,

示例12: createUpgradeMarkerFile

​點讚 2

import org.apache.commons.io.FileUtils; //導入方法依賴的package包/類

private static void createUpgradeMarkerFile() {

try {

FileUtils.touch(new File(DB_UPGRADE_IN_PROGRESS_MARKER_FILE));

} catch (IOException e) {

log.error("Fail to create upgrade in progress marker file");

}

}

開發者ID:opensecuritycontroller,項目名稱:osc-core,代碼行數:8,

示例13: empty_file

​點讚 2

import org.apache.commons.io.FileUtils; //導入方法依賴的package包/類

@Test

public void empty_file() throws Exception {

File tempFile = temp.newFile();

FileUtils.touch(tempFile);

FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, StandardCharsets.UTF_8);

assertThat(metadata.lines).isEqualTo(1);

assertThat(metadata.originalLineOffsets).containsOnly(0);

assertThat(metadata.lastValidOffset).isEqualTo(0);

}

開發者ID:instalint-org,項目名稱:instalint,代碼行數:11,

示例14: buildFileDatas

​點讚 2

import org.apache.commons.io.FileUtils; //導入方法依賴的package包/類

protected List buildFileDatas(String namespace, EventType eventType, int start, int count, boolean create)

throws IOException {

List files = new ArrayList();

for (int i = start; i < count; i++) {

FileData fileData = new FileData();

fileData.setNameSpace(namespace); // namespace is null means file is

// local file

fileData.setEventType(eventType);

fileData.setPairId(i % NUMBER_OF_FILE_DATA_COPIES);

fileData.setPath(ROOT_DIR.getAbsolutePath() + "/target/" + eventType.getValue() + i);

String parentPath = ROOT_DIR.getPath();

if (namespace != null) {

parentPath = parentPath + "/" + namespace;

}

File file = new File(parentPath, fileData.getPath());

if (!file.exists() && create) {

FileUtils.touch(file);

}

fileData.setSize(file.exists() ? file.length() : 0);

fileData.setLastModifiedTime(file.exists() ? file.lastModified() : Calendar.getInstance().getTimeInMillis());

fileData.setTableId(TABLE_ID);

files.add(fileData);

}

return files;

}

開發者ID:luoyaogui,項目名稱:otter-G,代碼行數:31,

示例15: processTemplate

​點讚 2

import org.apache.commons.io.FileUtils; //導入方法依賴的package包/類

/**

* 處理模板生成.

*

* @param model model

* @param files files

* @param templateDirectory templateDirectoryFile

* @throws IOException io exception

*/

private void processTemplate(FreemarkerHelper templateHelper, Map model, List files,

File templateDirectory) throws IOException {

for (File file : files) {

String fileName = file.getName();

String targetName = templateHelper.processToString(model, fileName.replace(FREEMARKER_TEMPLATE_SUFFIX, ""));

File targetFile = getTargetFile(templateHelper, model, templateDirectory, file, outDirectoryFile,

targetName);

FileUtils.touch(targetFile);

String templateName = getRelativizeTemplateFile(templateDirectory, file).toPath().toString();

templateHelper.processToFile(model, templateName, targetFile, "UTF-8");

}

}

開發者ID:sgota,項目名稱:tkcg,代碼行數:21,

示例16: create

​點讚 2

import org.apache.commons.io.FileUtils; //導入方法依賴的package包/類

public static void create() {

try {

FileUtils.touch(new File(Main.LOCK_FILE));

} catch (Exception e) {

e.printStackTrace();

// TODO do smth

}

}

開發者ID:mbrlabs,項目名稱:gdx-splash,代碼行數:9,

示例17: init

​點讚 2

import org.apache.commons.io.FileUtils; //導入方法依賴的package包/類

@BeforeClass

public void init () throws IOException,

DataStoreLocalArchiveNotExistingException, InterruptedException

{

tmp = Files.createTempDir();

tmp.mkdirs ();

HierarchicalDirectoryBuilder db =

new HierarchicalDirectoryBuilder (tmp, 100);

int i=1000;

while (i-->0)

{

File root = db.getDirectory ();

FileUtils.touch (new File(root, "toto.txt"));

FileUtils.touch (new File(root,

HierarchicalDirectoryBuilder.DHUS_ENTRY_NAME));

new File(root, "directory").mkdirs ();

}

// Set info coming from system configuration

max_no = cfgManager.getArchiveConfiguration().getIncomingConfiguration().getMaxFileNo();

incoming_root = new File(cfgManager.getArchiveConfiguration().getIncomingConfiguration().getPath()).getAbsoluteFile();

String[] folders_to_test_true =

{

incoming_root.getAbsolutePath() + "/X1",

incoming_root.getAbsolutePath() + "/X2",

incoming_root.getAbsolutePath() + "/X3",

incoming_root.getAbsolutePath() + "/X4",

incoming_root.getAbsolutePath() + "/X1/X1/X1/X1/X1/X1/X1/X1/X1",

incoming_root.getAbsolutePath() + "/X1/X2/X3/X4/X5/X6/X7/X8/X9",

incoming_root.getAbsolutePath() + "/X1/X1/X1/XAF/X1/X1/X1/X1/X1/",

incoming_root.getAbsolutePath() + File.separator + Long.toHexString(max_no - 1).substring(1),

incoming_root.getAbsolutePath() + "/X1/X1/X1/X1/X1/X1/" + HierarchicalDirectoryBuilder.DHUS_ENTRY_NAME,

incoming_root.getAbsolutePath() + "/X1/X1/X1/X1/X1/X1/" + HierarchicalDirectoryBuilder.DHUS_ENTRY_NAME + File.separator + IncomingManager.INCOMING_PRODUCT_DIR,

};

String[] folders_to_test_false =

{

"/tmp/toto",

incoming_root.getAbsolutePath () + "/my_data",

incoming_root.getAbsolutePath () + "/X2/X23453/X2/" + HierarchicalDirectoryBuilder.DHUS_ENTRY_NAME,

incoming_root.getAbsolutePath () + "/X3/" + HierarchicalDirectoryBuilder.DHUS_ENTRY_NAME + "/data",

incoming_root.getAbsolutePath () + "/X1/X1/X1/X1/X1/X1/" + HierarchicalDirectoryBuilder.DHUS_ENTRY_NAME + File.separator + IncomingManager.INCOMING_PRODUCT_DIR + File.separator + "mydata",

incoming_root.getAbsolutePath () + File.separator + max_no + "X1/X2/X3",

incoming_root.getAbsolutePath () + "/X3/data",

incoming_root.getAbsolutePath () + "/A4",

};

folders_to_test[0]=folders_to_test_true;

folders_to_test[1]=folders_to_test_false;

incomingPathChecker = new IncomingPathChecker ();

}

開發者ID:SentinelDataHub,項目名稱:dhus-core,代碼行數:55,

示例18: createNewParamterFile

​點讚 2

import org.apache.commons.io.FileUtils; //導入方法依賴的package包/類

private void createNewParamterFile(String file) throws IOException{

FileUtils.touch(new File(file));

}

開發者ID:capitalone,項目名稱:Hydrograph,代碼行數:4,

注:本文中的org.apache.commons.io.FileUtils.touch方法示例整理自Github/MSDocs等源碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。

 类似资料: