text-files

How do I populate JComboBox from a text file?

若如初见. 提交于 2019-11-27 09:37:32
How do I populate a JComboBox from a text file? Very vague question. Are you saying you want one entry per line? If so you want to use something like a BufferedReader, read all the lines, save them as a String array. Create a new JComboBox passing in that String constructor. BufferedReader input = new BufferedReader(new FileReader(filePath)); List<String> strings = new ArrayList<String>(); try { String line = null; while (( line = input.readLine()) != null){ strings.add(line); } } catch (FileNotFoundException e) { System.err.println("Error, file " + filePath + " didn't exist."); } finally {

Convert factor to integer in a data frame

不羁岁月 提交于 2019-11-27 09:09:53
I have the following code anna.table<-data.frame (anna1,anna2) write.table<-(anna.table, file="anna.file.txt",sep='\t', quote=FALSE) my table in the end contains numbers such as the following chr start end score chr2 41237927 41238801 151 chr1 36976262 36977889 226 chr8 83023623 83025129 185 and so on...... after that i am trying to to get only the values which fit some criteria such as score less than a specific value so i am doing the following anna3<-"data/anna/anna.file.txt" anna.total<-read.table(anna3,header=TRUE) significant.anna<-subset(anna.total,score <=0.001) Error: In Ops.factor

How to write textbox values to .txt file with vb.net

不想你离开。 提交于 2019-11-27 08:47:35
I have a simple form with two textboxes, I want Textbox1 to write to a file named C:\VALUE1.txt and Textbox2 to write its value to a file named C:\VALUE2.txt Any text that is already in the text file MUST be over written. It's worth being familiar with both methods: 1) In VB.Net you have the quick and easy My.Computer.FileSystem.WriteAllText option: My.Computer.FileSystem.WriteAllText("c:\value1.txt", TextBox1.Text, False) 2) Or else you can go the "long" way round and use the StreamWriter object. Create one as follows - set false in the constructor tells it you don't want to append: Dim

What is the fastest way to count lines and words in a text file in ANSI C?

一笑奈何 提交于 2019-11-27 08:15:36
问题 What is the fastest way to count lines and words in a text file in pure ANSI C? A word is terminated by a space or period. Line is terminated by '\n' . This seems to be in C++. 回答1: Maybe take a look at the source code of the GNU wc utility as this utility does exactly what you want. #include <stdlib.h> #include <stdio.h> #include <stdarg.h> typedef unsigned long count_t; /* Counter type */ /* Current file counters: chars, words, lines */ count_t ccount; count_t wcount; count_t lcount; /*

Converting a txt File from ANSI to UTF-8 programmatically

99封情书 提交于 2019-11-27 07:41:49
问题 I need your help here please. I'm working on a java application that convert data from a txt file into the database , The problem is that the file have ANSI encoding which i can't change because it comes from outside my application ,and when i write the data to the database i got some "???" inside. My question is , how can i convert the data that i read from the file from ANSI to UTF-8 which can handle those weired symbols. I've tried the Byte[] to String converting but it didn't work. 回答1:

Read a local text file using Javascript

被刻印的时光 ゝ 提交于 2019-11-27 07:38:19
I have read some of the previous questions on this topic but I really need to be 100% sure! Is it possible to read from a .txt file on my local system and present it in my HTML-BODY? I have tried several functions, here is one: function readFile (path) { var fso = new ActiveXObject('Scripting.FileSystemObject'), iStream=fso.OpenTextFile(path, 1, false); while(!iStream.AtEndOfStream) { document.body.innerHTML += iStream.ReadLine() + '<br/>'; } iStream.Close(); } readFile("testing.txt"); The content of the file is simply around 100 words I want to read from the text file and display in my HTML

Open a text file in the default text editor… via Java?

社会主义新天地 提交于 2019-11-27 07:17:45
OK. Simple question. Maybe not so simple answer, though: I have a file I downloaded in Java, and I know that it's a text file. Is there any way that I can use Java to open that text file in whatever the default text editor is? It has to work for all OS's, otherwise I would just make it open with Notepad. :\ I guess that if there's no way to do this I could use JOptionPane and show the contents of the text file... You can do that with: java.awt.Desktop.getDesktop().edit(file); This links to the tutorial article on java.awt.Desktop : Java™ Standard Edition version 6 narrows the gap between

How do I perform binary search on a text file to search a keyword in python?

假装没事ソ 提交于 2019-11-27 07:01:30
问题 The text file contains two columns- index number(5 spaces) and characters(30 spaces). It is arranged in lexicographic order. I want to perform binary search to search for the keyword. 回答1: Here's an interesting way to do it with Python's built-in bisect module. import bisect import os class Query(object): def __init__(self, query, index=5): self.query = query self.index = index def __lt__(self, comparable): return self.query < comparable[self.index:] class FileSearcher(object): def __init__

How to monitor a text file in realtime [closed]

夙愿已清 提交于 2019-11-27 06:31:43
For debugging purposes in a somewhat closed system, I have to output text to a file. Does anyone know of a tool that runs on windows (console based or not) that detects changes to a file and outputs them in real-time? Tail for Win32 Apache Chainsaw - used this with log4net logs , may require file to be in a certain format I like tools that will perform more than one task, Notepad++ is a great notepad replacement and has a Document Monitor plugin (installs with standard msi) that works great. It also is portable so you can have it on a thumb drive for use anywhere. For a command line option,

Unix one-liner to swap/transpose two lines in multiple text files?

不问归期 提交于 2019-11-27 06:25:20
问题 I wish to swap or transpose pairs of lines according to their line-numbers (e.g., switching the positions of lines 10 and 15) in multiple text files using a UNIX tool such as sed or awk. For example, I believe this sed command should swap lines 14 and 26 in a single file: sed -n '14p' infile_name > outfile_name sed -n '26p' infile_name >> outfile_name How can this be extended to work on multiple files? Any one-liner solutions welcome. 回答1: This might work for you (GNU sed): sed -ri '10,15!b