can I check if a file exists at a URL?

If you’re attempting to verify the existence of a web resource, I would recommend using the HttpWebRequest class. This will allow you to send a HEAD request to the URL in question. Only the response headers will be returned, even if the resource exists. var url = “”; HttpWebResponse response = null; var request = …

Read more

How can I read a file even when getting an “in use by another process” exception?

FileStream logFileStream = new FileStream(“c:\test.txt”, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); StreamReader logFileReader = new StreamReader(logFileStream); while (!logFileReader.EndOfStream) { string line = logFileReader.ReadLine(); // Your code here } // Clean up logFileReader.Close(); logFileStream.Close(); Original source for code

How to convert String to Reader in java

Use return new StringReader(string);. Next time you need a reader, you can check the “Direct known subclasses” of the Reader class. Same goes for InputStream, etc. The place to start is the javadoc – it contains quite a lot of useful information. But for your task at hand, you’d better follow Jon Lin’ advice …

Read more

LOAD DATA INFILE Error Code : 13

I know that this post is old, but this still comes up in search results. I couldn’t find the solution to this problem online, so I ended up figuring it out myself. If you’re using Ubuntu, then there is a program called “Apparmor” that is preventing MySQL from seeing the file. Here’s what you need …

Read more

How to check if a given path is possible child of another path?

You can also use java.nio.file.Path to do this much more easily. The java.nio.file.Path.startsWith method seems to handle all possible cases. Example: private static void isChild(Path child, String parentText) { Path parent = Paths.get(parentText).toAbsolutePath(); System.out.println(parentText + ” = ” + child.startsWith(parent)); } public static void main(String[] args) { Path child = Paths.get(“/FolderA/FolderB/File”).toAbsolutePath(); isChild(child, “/FolderA/FolderB/File”); isChild(child, “/FolderA/FolderB/F”); …

Read more

Whole text file to a String in Java

apache commons-io has: String str = FileUtils.readFileToString(file, “utf-8”); But there is no such utility in the standard java classes. If you (for some reason) don’t want external libraries, you’d have to reimplement it. Here are some examples, and alternatively, you can see how it is implemented by commons-io or Guava.

Getting filename (or path) from fstream

No, that is not possible, not at least in the Standard conformant implementation of the library. The fstream class doesn’t store the filename, and doesn’t provide any function for retrieving it. So one way to keep track of this information is to use std::map as: std::map<std::fstream*, std::string> stream_file_table; void f() { //when you open a …

Read more

How to copy a file to another path?

Have a look at File.Copy() Using File.Copy you can specify the new file name as part of the destination string. So something like File.Copy(@”c:\test.txt”, @”c:\test\foo.txt”); See also How to: Copy, Delete, and Move Files and Folders (C# Programming Guide)