file-io

how to update the contain in .txt file java [closed]

大兔子大兔子 提交于 2020-01-21 08:31:11
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . for example i have the file named file.txt which contain personal information (id,name, salary): A123 Anna 3000 A234 Alex 4000 A986 Jame 5000 How can I write a java code that allow user to enter an ID of a person

std::string equivalent for data with null characters?

吃可爱长大的小学妹 提交于 2020-01-21 07:53:45
问题 I'd like to read a binary file and use something like std::string that automatically resizes the buffer and such. I'm using Visual C++. What are my options? 回答1: std::string should be safe to do so... you only have to be careful using .c_str() method. Use .data() . 回答2: The std::string class already does handle data with embedded NUL characters. What problem are you encountering? Note that when using the .c_str() method, any embedded NUL character will terminate the returned C-style string.

Libgdx How to get a list of files in a directory?

混江龙づ霸主 提交于 2020-01-21 02:43:06
问题 So I am trying to get a list of files in a directory with a file handle.list() method but it returns an empty list even though there are files in the directory. What seems strange to me is that it does work on the device but it does not work on the desktop. I think I know what the problem is but I dont know how to solve it though. In the method description it says "On the desktop, an FileType.Internal handle to a directory on the classpath will return a zero length array.", but there is no

Libgdx How to get a list of files in a directory?

风流意气都作罢 提交于 2020-01-21 02:43:06
问题 So I am trying to get a list of files in a directory with a file handle.list() method but it returns an empty list even though there are files in the directory. What seems strange to me is that it does work on the device but it does not work on the desktop. I think I know what the problem is but I dont know how to solve it though. In the method description it says "On the desktop, an FileType.Internal handle to a directory on the classpath will return a zero length array.", but there is no

How to test write to file in Java?

与世无争的帅哥 提交于 2020-01-21 00:42:26
问题 I'm beginner, and keep yourself in hands. I have some easy program, and I need do junit test for write method. I have some collection in input. How I can do this? This my code: // write to file public void write(String fileName, List<FigureGeneral> figuresList) { try { PrintWriter out = new PrintWriter( new File(fileName).getAbsoluteFile()); try { for (int i = 0; i < figuresList.size(); i++) { out.println(figuresList.get(i).toString()); } } finally { out.close(); } } catch (IOException e) {

Python not writing full string to file

江枫思渺然 提交于 2020-01-20 08:04:24
问题 I am attempting to output an aligned protein sequence to a file, however, the output string is truncated each time I attempt to write the string to file. The string I'm attempting to write is 4603 characters long, and is printed to the console with the correct number of characters. The first snippet of code I'm attaching pertains to the output variable itself. I'm going to include the full strings here, because the way in which the strings are truncated upon writing to a file have been

Python not writing full string to file

时光毁灭记忆、已成空白 提交于 2020-01-20 08:02:00
问题 I am attempting to output an aligned protein sequence to a file, however, the output string is truncated each time I attempt to write the string to file. The string I'm attempting to write is 4603 characters long, and is printed to the console with the correct number of characters. The first snippet of code I'm attaching pertains to the output variable itself. I'm going to include the full strings here, because the way in which the strings are truncated upon writing to a file have been

reading input till EOF in java

女生的网名这么多〃 提交于 2020-01-20 02:47:05
问题 In C++ if I wish to read input till the EOF I can do it in the following manner while(scanf("%d",&n)) { A[i]=n; i++; } I can then run this code as ./a.out < input.txt. What is the java equivalent of this code? 回答1: You can do this: Scanner s = new Scanner(System.in); while (s.hasNextInt()) { A[i] = s.nextInt(); i++; } 回答2: // assuming that reader is an instance of java.io.BufferedReader String line = null; while ((line = reader.readLine()) != null) { // do something with every line, one at a

In C++, what is the proper way to insert a line at the beginning of a text file?

一世执手 提交于 2020-01-19 06:07:25
问题 I am creating a large text file, the first line is a summary which depends on the contents. I am currently inserting a summary line that contains what I expect the summary to be, and after creating the file I compare this with what was actually written. If the information is different I overwrite the initial summary. Code follows. std::ofstream ofile(filename); numOutSegInSynth-=computeSegmentsFromLevel(numLevelsInSynth-1,myInitCkt); //extra padding inserted, to prevent summary overwriting

Can select() be used with files in Python under Windows?

∥☆過路亽.° 提交于 2020-01-19 05:42:46
问题 I am trying to run the following python server under windows: """ An echo server that uses select to handle multiple clients at a time. Entering any line of input at the terminal will exit the server. """ import select import socket import sys host = '' port = 50000 backlog = 5 size = 1024 server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server.bind((host,port)) server.listen(backlog) input = [server,sys.stdin] running = 1 while running: inputready,outputready,exceptready = select