Reading entire file to QString

As pointed out, there is no such constructor for QTextStream. I quickly typed those few lines to verify it is indeed working properly: foreach (QString file, files) { QFile f(file); if (!f.open(QFile::ReadOnly | QFile::Text)) break; QTextStream in(&f); qDebug() << f.size() << in.readAll(); } And I do get the expected output – the size and content … Read more

How to add a Browse To File dialog to a VB.NET application

You should use the OpenFileDialog class like this Dim fd As OpenFileDialog = New OpenFileDialog() Dim strFileName As String fd.Title = “Open File Dialog” fd.InitialDirectory = “C:\” fd.Filter = “All files (*.*)|*.*|All files (*.*)|*.*” fd.FilterIndex = 2 fd.RestoreDirectory = True If fd.ShowDialog() = DialogResult.OK Then strFileName = fd.FileName End If Then you can use the … Read more

reading text file with utf-8 encoding using java

Use import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; public class test { public static void main(String[] args){ try { File fileDir = new File(“PATH_TO_FILE”); BufferedReader in = new BufferedReader( new InputStreamReader(new FileInputStream(fileDir), “UTF-8”)); String str; while ((str = in.readLine()) != null) { System.out.println(str); } in.close(); } catch (UnsupportedEncodingException e) { … Read more

is there an existing FileInputStream delete on close?

I know this is a fairly old question; however, it’s one of the first results in Google, and Java 7+ has this functionality built in: Path path = Paths.get(filePath); InputStream fileStream = Files.newInputStream(path, StandardOpenOption.DELETE_ON_CLOSE); There are a couple caveats with this approach though, they’re written up here, but the gist is that the implementation makes … Read more